_import("java.nio.file.Files")
_import("java.time.LocalDate")

var yyyy_MM_dd_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
var yyyyMMdd_PARSER = new SimpleDateFormat("yyyyMMdd");
var yyyy_MM_dd_HH_mm_ss_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
var debitlist = new ArrayList();
var creditlist = new ArrayList();
var retryTimes = 0;
var smsRetryTimes = 0;

var v4_icbc_java_funcs = {
    openHomePage : function(){
        resetContext()
        luaFuncs.clearTemp()
        luaFuncs.setSizeAndShow();
        var loginIframe = get("https://mybank.icbc.com.cn/icbc/newperbank/perbank3/frame/frame_index.jsp");
        luaFuncs.closeIndexHelp()
        //打开首页
        context.put("loginIframe", loginIframe)
        storeDataToFile(context, loginIframe, "loginIframe.html")

    },
    checkProxyAvailable: function() {
        var loginIframe = context.get("loginIframe")
        if (StringUtils.isBlank(loginIframe)
            || loginIframe.contains("代理服务器没有响应")
            || loginIframe.contains("使用搜索引擎查找页面")
            ||  loginIframe.contains("无法显示此页")
            || loginIframe.length() < 30) {
            return false;
        } else {
            return true;
        }

    },
    checkTargetWebsiteAvailable: function(){return true;},
    checkControlAvailable:function (){ return luaFuncs.checkControlAvailable()},
    needResetEnvironment :function () {
        context.put("proxyAvailable", false)
        return equals(context.get("currentErrorCode"), BALO_99602_50)
    },
    login:function () {
        typeUsername()
        //luaFuncs.clickImage();
        //输入图片验证码
        typeCaptcha()
        //输入密码
        typePassword()

        //点击登陆按钮
        clickLoginButtonAndCheckErrMsg();

        var pageCheckResult = JSON.parse(luaFuncs.whichPage())

        //广告
        if(Boolean.valueOf(pageCheckResult.get("isAD"))){
            closeFirstADIfExist()

            closeSecondADIfExist()

            checkPreInfo()
        //短信
        } else if(Boolean.valueOf(pageCheckResult.get("isSMS"))){

            typeSms();

            checkLoginTimeout()

            closeFirstADIfExist();

            closeSecondADIfExist()

            checkPreInfo()

        // 首页
        } else if(Boolean.valueOf(pageCheckResult.get("isINDEX"))) { //是首页的情况
            logger.info("任务【 {} 】,直接登录至首页", context.get(LUA_TASK_KEY))

        //超时页
        } else if(Boolean.valueOf(pageCheckResult.get("isTIMEOUT"))) {
            throwBankExceptionByErrorCode(BALO_99601_30)

        // 其他 及 空白页
        } else {
            throwBankExceptionByErrorCode(BALO_99601_30)
        }

        checkAtomServiceFail()

        getCurrentPage()

        onIndex()

    },
    crawl: crawl,
    exitLogin: function () {}
}

function getCurrentPage(){
    var accframeHtml = luaFuncs.get_html_gb2312();
    context.put("accframeHtml", accframeHtml);
    storeDataToFile(context, accframeHtml, "accframeHtml.html")
}

function checkPreInfo(){
    var preInfoCheckResult = JSON.parse(luaFuncs.checkPreInfo())

    var needSupportPreInfo = function(preInfoCheckResult) {
        return !Boolean.valueOf(preInfoCheckResult.get("hasPreInfo"))
    }

    var getPreInfoErrorMsg = function(preInfoCheckResult) {
        return preInfoCheckResult.get("preInfoMsg")
    }
    if(!assertTrue(preInfoCheckResult, needSupportPreInfo)){
        logger.info("任务【 {} 】,预留信息检查结果【 {} 】", context.get(LUA_TASK_KEY), getPreInfoErrorMsg(preInfoCheckResult))
    }
}

/**
 * 检查原子服务失败，更换代理重新登录
 */
function checkAtomServiceFail(){
    var atomServiceCheckResult = JSON.parse(luaFuncs.checkAtomServiceFail())

    var atomServiceSuccess = function(atomServiceCheckResult) {
        return !Boolean.valueOf(atomServiceCheckResult.get("flag"))
    }

    var getAtomServiceErrorMsg = function(preInfoCheckResult) {
        return preInfoCheckResult.get("errorMsg")
    }

    assertTrueOrThrowException(atomServiceCheckResult, atomServiceSuccess, getAtomServiceErrorMsg)
    logger.info("任务【 {} 】,原子服务检查结果【 {} 】", context.get(LUA_TASK_KEY), atomServiceCheckResult)
}

function checkLoginTimeout(){

    getCurrentPage()

    // var accframeHtml = FileUtils.readFileToString(new File("C:\\Users\\Test\\Desktop\\accframeHtml.html"), "GBK")
    var loginTimeOutCheckResult = Jsoup.parse(context.get("accframeHtml"))

    var isNotTimeout = function(loginTimeOutCheckResult) {
        var timeoutTip = StringUtils.trim(loginTimeOutCheckResult.select("body > div > div.zzhk-jnhk-right > div.zzhk-jnhk-info > ul > li:nth-child(2) > span:nth-child(2)").text())
        return !(StringUtils.isNotBlank(timeoutTip) && equals(timeoutTip, "提示信息： 您已超时退出，请您尝试重新进入此交易。"))
    }

    var getTimeoutErrorMsg = function(loginTimeOutCheckResult) {
        return StringUtils.trim(loginTimeOutCheckResult.select("body > div > div.zzhk-jnhk-right > div.zzhk-jnhk-info > ul > li:nth-child(2) > span:nth-child(2)").text())
    }
    assertTrueOrThrowException(loginTimeOutCheckResult, isNotTimeout, getTimeoutErrorMsg)
    logger.info("任务【 {} 】,登录超时检验通过", context.get(LUA_TASK_KEY))
}

/**
 * 输入账号
 */
function typeUsername(){
    logger.info("{},输入帐号",context.get(LUA_TASK_KEY))

    var typeUsernameResult = luaFuncs.typeUsername(getLoginParams(context)[0]);
    //检查密码输入是否正确
    var isUsernameCorrectFunc = function (typeUsernameResult) {
        return typeUsernameResult;
    }

    //密码输入不对  就是因为密码因控件输入错误
    var getUsernameErrorMsgFunc = function(typeUsernameResult) {
        return "用户名未正确输入"
    }

    assertTrueOrThrowException(typeUsernameResult, isUsernameCorrectFunc, getUsernameErrorMsgFunc)
    logger.info("任务【 {} 】用户名输入成功", context.get(LUA_TASK_KEY));
}

/**
 * 输入密码
 * @returns {boolean}
 */
function typePassword(){

    show()
    var typePwdResult = luaFuncs.typePassword(context.get(LUA_TASK_TOKEN))
    hide()

    //检查密码输入是否正确
    var isPassWordCorrectFunc = function (typePwdResult) {
        return typePwdResult;
    }

    //密码输入不对  就是因为密码因控件输入错误
    var getPasswordErrorMsgFunc = function(typePwdResult) {
        return "密码因控件输入错误"
    }

    assertTrueOrThrowException(typePwdResult, isPassWordCorrectFunc, getPasswordErrorMsgFunc)
    logger.info("任务【 {} 】密码输入成功", context.get(LUA_TASK_KEY));

}

function typeCaptcha() {

    //获取图片验证码路径
    var captchaResult = JSON.parse(luaFuncs.getImagecodePath());

    logger.info("任务【 {} 】图片验证码路径【 {} 】", context.get(LUA_TASK_KEY), captchaResult.get("path"))
    var isCaptchaPathCorrectFunc = function(captchaResult) {
        return Boolean.valueOf(captchaResult.get("flag"))
    }

    var getCaptchaPathErrorMsgFunc = function(captchaResult) {
        return "图片验证码获取失败"
    }

    assertTrueOrThrowException(captchaResult, isCaptchaPathCorrectFunc, getCaptchaPathErrorMsgFunc)
    logger.info("任务【 {} 】图片验证码获取成功", context.get(LUA_TASK_KEY))

    context.put(TASK_IMG_PATH, captchaResult.get("path"));
    context.put(TASK_IMG_REGEX,"[0-9a-zA-Z]{4}");
    var code = waitImgCodeBySecondsByJs(context,60,true,3);

    var typeCaptchaResult = luaFuncs.typeCaptcha(code.toLowerCase())
    logger.info("任务【 {} 】图片验证码路径【 {} 】", context.get(LUA_TASK_KEY), captchaResult.get("path"))
    var isTypeCaptchaCorrectFunc = function(typeCaptchaResult) {
        return typeCaptchaResult
    }

    var getTypeCaptchaErrorMsgFunc = function(typeCaptchaResult) {
        return "图片验证码输入错误"
    }

    assertTrueOrThrowException(typeCaptchaResult, isTypeCaptchaCorrectFunc, getTypeCaptchaErrorMsgFunc)

}

/**
 * 点击登陆出现的信息
 * @returns {boolean}
 */
function clickLoginButtonAndCheckErrMsg(){
    logger.info("{},点击登陆按钮",context.get(LUA_TASK_KEY));

    var clickResult = luaFuncs.clickLoginButton();
    storeDataToFile(context, clickResult, "clickResult.html");


    var pageChangeResult = JSON.parse(clickResult)
    //检查页面是否跳转，跳转说明可能是成功、否则一定是失败
    var isPageChangedFunc = function (pageChangeResult) {
        return Boolean.valueOf(pageChangeResult.get("flag"))
    }

    //检查登陆出现的错误信息
    var getLoginErrorMsgFunc = function(pageChangeResult) {
        if(equals(StringUtils.trim(pageChangeResult.get("errorMsg")), "")) {
            return "登录超时"
        } else {
            return pageChangeResult.get("errorMsg")
        }

    }

    //断言
    assertTrueOrThrowException(pageChangeResult, isPageChangedFunc, getLoginErrorMsgFunc)
}

/**
 * 检查是否需要输入短信
 */
/*function checkIfSmsNeedType() {
    var inputSmsHtml = luaFuncs.get_html_gs();
    storeDataToFile(context, inputSmsHtml, "inputSmsHtml.html");
    return inputSmsHtml.contains("短信认证");
}*/

/**
 * 点击短信认证Span
 * @returns {boolean}
 */
function clickSmsSpan() {

    //TODO: checkSpanName
    var smsSpanExist = luaFuncs.clickSmsSpan();
    logger.info("工商银行 taskKey: {} 切换到输入短信页面{}",  context.get(LUA_TASK_KEY), Boolean.valueOf(smsSpanExist) ? "成功" : "失败");

    if(!Boolean.valueOf(smsSpanExist)){
        var htmlPath = luaFuncs.get_picture_gs();
        logger.info("工商银行 taskKey: {} 登录信息：第二步点击短信认证返回的是false  截图-路径: {}",  context.get(LUA_TASK_KEY), htmlPath);

        var smsHtml = luaFuncs.getSecondLoginHtmlMsg();
        storeDataToFile(context, smsHtml, "smsHtml.html");
        /*var taskKey = context.get(LUA_TASK_KEY);
        var year = taskKey.substring(0, 2);
        var month = taskKey.substring(2, 4);
        var day = taskKey.substring(4, 6);

        var filePath = PropertyManager.getRB("htmlStorage", "home_path") +
            "/" +
            "BANK" +
            "/" +
            year +
            "/" +
            month +
            "/" +
            day +
            "/" +
            taskKey +
            "/" +
            "smsHtml.html";
        FileUtils.writeStringToFile(new File(filePath), smsHtml, "GBK",false);   不能用编码格式GBK*/
        //TODO 没有tab页的两种情况　１＞　口令（Ｕ盾）＝＝　抛异常　２〉短信　＝＝　直接走流程
        //没有tab页的情况
        var isCorrectFunc = function (smsHtml) {

            return smsHtml.contains("请您输入短信验证码");
        }

        //检查登陆出现的错误信息
        var getErrorMsgFunc = function(smsHtml) {
               if(smsHtml.contains("请您使用电子密码器")){
                   return "请您使用电子密码器"
               }else if(smsHtml.contains("请您使用U盾进行认证")){
                   return "请您使用U盾进行认证"
               }else if(smsHtml.contains("请您使用口令卡进行认证")){
                   return "请您使用口令卡进行认证"
               }else if (smsHtml.contains("请您尝试重新进入此交易")){
                   return "提示信息： 您已超时退出，请您尝试重新进入此交易。"
               }else {
                   return "提示信息： 您已超时退出，请您尝试重新进入此交易。"
               }
        }

      return assertTrueOrThrowException(smsHtml, isCorrectFunc, getErrorMsgFunc)

    }else {
        return Boolean.valueOf(smsSpanExist);
    }
}

/**
 * 获取图片验证码并输入
 * @returns {boolean}
 */
function getImgCodeAndTypeIt() {
    var imgPath = luaFuncs.getSmsCaptcha();
    logger.info("工商银行 taskKey： {} 短信验证页面获得图片验证码路径： {}",  context.get(LUA_TASK_KEY), imgPath);

    //检验图片路径是否获取到
    var isImgCorrectFunc = function(imgPath){
        return !equals(imgPath, "nil")
    }

    //图片验证码获取失败　　重新来一遍
    var isImgErrorMsgFunc = function(imgPath) {
        return "图片验证码获取失败"
    }

    assertTrueOrThrowException(imgPath, isImgCorrectFunc, isImgErrorMsgFunc)
    logger.info("{} 验证页面图片验证码获取成功,路径： {}",  context.get(LUA_TASK_KEY), imgPath)


    context.put(TASK_IMG_PATH, imgPath)
    context.put(TASK_IMG_REGEX,"[0-9a-zA-Z]{4}")

    // var code = waitImgCodeBySecondsByJs(context, 60, true, 3);
    var codeRetryTimes = 0
    var code
    do{
        code = wait4ImgCodeBySeconds(context, 60)
        codeRetryTimes++
    }while(code == null && codeRetryTimes <= 3)

    if(code == null){
        code = waitImgCodeBySecondsByJs(context, 60, true, 3)
    }

    logger.info("工商银行 taskKey: {} 图片验证码返回信息：{},codeRetryTimes={}",  context.get(LUA_TASK_KEY), code,codeRetryTimes)


    show()
    var typeResult = luaFuncs.typeSmsCaptcha(code.toLowerCase())
    hide();

    var isImgCorrectFunc = function(typeResult){
        return typeResult
    }

    //图片验证码获取失败　　重新来一遍
    var isImgErrorMsgFunc = function(typeResult) {
        return "密码因控件输入错误"
    }

    assertTrueOrThrowException(typeResult, isImgCorrectFunc, isImgErrorMsgFunc);
    logger.info("{} 短信验证页面图片验证码获取成功,路径： {}",  context.get(LUA_TASK_KEY));
}

function resetContext(){
    context.put("hasSendSms", "false")
    context.put("smsSendResult", null)
}

function sendSms() {
    var smsSendResult
    if(!Boolean.valueOf(context.get("hasSendSms"))) {
        smsSendResult = JSON.parse(luaFuncs.sendSms())
        logger.info("工商银行 taskKey： {} ，发送短信结果{}",  context.get(LUA_TASK_KEY), smsSendResult);
        context.put("hasSendSms", "true");
        context.put("smsSendResult", smsSendResult)
    } else {
        smsSendResult = context.get("smsSendResult")
    }
}
/**
 * 发送短信并且输入
 * @returns {boolean}
 */
function typeReceivedSms() {
    var smsSendResult = context.get("smsSendResult")

    //flag true 表示需要输入短信 false 表示不需要输入
    if(Boolean.valueOf(smsSendResult.get("flag"))){
        var isSendSmsCorrectFunc = function(smsSendResult){
            //可以发送短信且未达到上限
            return !Boolean.valueOf(smsSendResult.get("isLimit"))
        }

        var sendSmsGetErrorMsgFunc = function (smsSendResult) {
            return smsSendResult.get("errorMsg")
        }
        assertTrueOrThrowException(smsSendResult,isSendSmsCorrectFunc,sendSmsGetErrorMsgFunc);

        // 等待短信验证码
        var smsCode = waitSmsCodeBySeconds(context, 120);
        var typeSmsSuccess = luaFuncs.typeSms(smsCode);
        logger.info("{}, 输入短信验证码{}",  context.get(LUA_TASK_KEY), Boolean.valueOf(typeSmsSuccess) ? "成功" : "失败");

        var isReceviceSmsCorrectFunc = function(typeSmsSuccess){
            return Boolean.valueOf(typeSmsSuccess);
        }

        var receviceSmsGetErrorMsgFunc = function (typeSmsSuccess) {
            return "短信输入失败"
        }
        assertTrueOrThrowException(typeSmsSuccess,isReceviceSmsCorrectFunc,receviceSmsGetErrorMsgFunc);

    }

}

/**
 * 点击确定按钮
 * @returns {boolean}
 */
function clickConfirmButton() {
    var clickConfirmButtonSuccess = luaFuncs.clickConfirmButton();
    logger.info("工商银行 taskKey: {} 登录是否成功{}", context.get(LUA_TASK_KEY), Boolean.valueOf(clickConfirmButtonSuccess) ? "成功" :"失败");


    var isClickConfirmButtonSuccessCorrectFunc = function(clickConfirmButtonSuccess){
        return Boolean.valueOf(clickConfirmButtonSuccess);
    }

    var clickConfirmButtonGetErrorMsgFunc = function(clickConfirmButtonSuccess){
        return '确定按钮不存在'
    }
    assertTrueOrThrowException(clickConfirmButtonSuccess,isClickConfirmButtonSuccessCorrectFunc,clickConfirmButtonGetErrorMsgFunc);
}

/**
 * 选择我的电脑 点击单选按钮  否 然后点击继续按钮
 * @returns {boolean}
 */
function clickRadioAndGoOnButton() {
    //show();
    var changeRadioResult = JSON.parse(luaFuncs.changeRadio())
    //hide();

    logger.info("工商银行 taskKey： {} 选择我的电脑 改变单选按钮为否: 【 {} 】", context.get(LUA_TASK_KEY), Boolean.valueOf(changeRadioResult.get("changed")) ? "成功":"失败");

    var isChangeRadioSuccessFunc = function(changeRadioResult){
        return Boolean.valueOf(changeRadioResult.get("flag"));
    }
    var getChangeRadioErrorMsgFunc = function(changeRadioResult){
        return '单选按钮不存在'
    }
    assertTrueOrThrowException(changeRadioResult, isChangeRadioSuccessFunc, getChangeRadioErrorMsgFunc);

    luaFuncs.clickGoOnButton();

}

function typeSms() {

    var contentWillBeCheckedFunc = function() {
        if(clickSmsSpan()){
            //hide();
            //发短信
            sendSms()
            //获取识别图片验证码
            getImgCodeAndTypeIt();
            //输入短信
            typeReceivedSms();
            //点击确定按钮
            clickConfirmButton();

            return JSON.parse(luaFuncs.getConfirmErrorMsg())
        } else {
            return JSON.parse("{\"flag\":\"false\"}")
        }
    }

    var isCorrectFunc = function(contentWillBeChecked){
         return !Boolean.valueOf(contentWillBeChecked.get("flag"))
    }

    var getErrorMsgFunc = function(contentWillBeChecked){

        if(contentWillBeChecked.get("errorMsg").contains("反复输入手机短信认证码")
            || contentWillBeChecked.get("errorMsg").contains("提示信息： 对不起，您的短信验证码错误或超过有效时间。") ){
            canRetryErrorCodeRetryTime['BALO-99602-40'][0] = 3  //设置短信错误次数为3
            canRetryErrorCodeRetryTime['BALO-21001-35'][0] = 3 //设置图片错误次数为3
            return "短信验证码错误"
        }
        return StringUtils.trim(contentWillBeChecked.get("errorMsg"))
    }

    repeaterAndAssertTrueOrThrowException(contentWillBeCheckedFunc, isCorrectFunc, getErrorMsgFunc, 4)

    clickRadioAndGoOnButton()

}

/**
 * 登录成功的首页
 **/
function onIndex() {

    var accframeHtml = context.get("accframeHtml")
    //TODO: 处理超时退出的逻辑
    var frameMap = new HashMap();
    //解析首页dse_sessionId
    paraseBillParams(accframeHtml, frameMap);
    var frameHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCPERBANKLocationServiceServlet", frameMap));
    context.put("frameHtml", frameHtml);
    storeDataToFile(context, frameHtml, "frameHtml.html")
    var cardListHtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn/icbc/newperbank/account/account_list_regacct.jsp?dse_sessionId=" + frameMap.get("dse_sessionId")));
    storeDataToFile(context, cardListHtml, "cardList.html")
    context.put("cardListHtml", cardListHtml);


    //借记卡信息
    var doc = Jsoup.parse(cardListHtml);

    logger.info("{},debitHtml页面是否存在title标签={}",context.get(LUA_TASK_KEY),doc.getElementsByTag("title").text());
    if(StringUtils.isNotBlank(doc.getElementsByTag("title").text())){
        var title = doc.getElementsByTag("title").text();
        // var title = titles.text();
        logger.info("{},debitHtml页面中的显示title={}",context.get(LUA_TASK_KEY),title);
        if (title.contains("申请办卡")) {
            logger.info("工商银行 taskKey： {} 首页信息：节点信息-用户未注册", taskKey);
            throw new BankException(BankConstants.BALO_20304_30,"未获取到卡片信息，请登录官网绑定卡片");
        }else if(title.contains("个人网上银行-我的账户")){
            return true;
        }else {
            throw new BankException(BankConstants.BACR_99601_60,title);
        }
    }else {
        throw new BankException(BankConstants.BALO_22101_10,"尚未注册无此用户");

    }

}

/**
 * 关闭首页之前的第一个广告
 */
function closeFirstADIfExist() {

    var contentWillBeCheckedFunc = function() {
        return luaFuncs.closeFirstAD();
    }

    var isCorrectFunc = function(contentWillBeChecked) {
        return contentWillBeChecked
    }

    repeater(contentWillBeCheckedFunc, isCorrectFunc, 3)

}

function closeSecondADIfExist(){

    var contentWillBeCheckedFunc = function() {
        return luaFuncs.closeSecondAD();
    }

    var isCorrectFunc = function(contentWillBeChecked) {
        return contentWillBeChecked
    }

    repeater(contentWillBeCheckedFunc, isCorrectFunc, 3)
}

function paraseBillParams(accframeHtml, frameMap) {
    var doc = Jsoup.parse(accframeHtml);
    var topfameFroms = doc.select("[name='topfameFrom']");
    if(topfameFroms.size() > 0){
        try {
            var topfameFrom = topfameFroms.get(0);
            var dse_sessionIds = topfameFrom.select("[name='dse_sessionId']");
            var dse_sessionId = dse_sessionIds.get(0).attr("value");
            var requestChannels = topfameFrom.select("[name='requestChannel']");
            var requestChannel = requestChannels.get(0).attr("value");
            var transDatas = topfameFrom.select("[name='transData']");
            var transData = transDatas.get(0).attr("value");
            var zoneNos = topfameFrom.select("[name='zoneNo']");
            var zoneNo = zoneNos.get(0).attr("value");
            var isflots = topfameFrom.select("[name='isflot']");
            var isflot = isflots.get(0).attr("value");
            var Languages = topfameFrom.select("[name='Language']");
            var Language = Languages.get(0).attr("value");
            var serviceIdIntos = topfameFrom.select("[name='serviceIdInto']");
            var serviceIdInto = serviceIdIntos.get(0).attr("value");
        } catch (e) {
            logger.error("工商银行 taskKey:{} paraseBillParams()方法中 获取map参数时解析出错！",context.get(LUA_TASK_KEY));
            statCaughtException(context, e);
        }
        frameMap.put("dse_sessionId", dse_sessionId);
        frameMap.put("requestChannel", requestChannel);
        frameMap.put("transData", transData);
        frameMap.put("zoneNo", zoneNo);
        frameMap.put("isflot", isflot);
        frameMap.put("Language", Language);
        frameMap.put("serviceIdInto", serviceIdInto);
        frameMap.put("serviceId", "PBL201786");
    }else{
        logger.info("工商银行 taskKey:{} paraseBillParams()方法中 topfameFroms.size() = 0",context.get(LUA_TASK_KEY));
    }

}

function checkErrorHtml() {
    var checkSuccessFulQuitHtml = context.get("checkSuccessFulQuit");
    if (checkSuccessFulQuitHtml.contains("根据客户指令，本次登录强行退出") || checkSuccessFulQuitHtml.contains("您已经成功退出")) {
        return true;
    }
    return false;
}

/**
 * 检查卡列表是否有信用卡信息
 * @param debitHtml
 * @returns {boolean}
 */
function checkIfContainsCreditCards(debitHtml){
    try{
        var accframeHtml = context.get("accframeHtml");
        var flag = false;
        var doc = Jsoup.parse(debitHtml);
        var kabaos = doc.select("[class='kabao-main-item kabao-main-item1']");
        for (var j = 0; j < kabaos.size(); j++) {
            var li = kabaos.get(j).attr("id");
            var kabaoElt = kabaos.get(j);
            var liTxt = kabaoElt.getElementsByTag("li").get(0).text();
            if (!liTxt.equals("明细")) {
                continue;
            }
            var cardType = kabaoElt.getElementsByTag("h6").text();
            if (cardType.contains("电子账户") || cardType.contains("中国农业银行")|| cardType.contains("人民币e卡")) {
                logger.info("工商银行 taskKey: {} 卡片信息：此卡为电子账户", context.get(LUA_TASK_KEY));
                continue;
            }
            if (kabaoElt.text().contains("距离还款日")) {
                flag = true;
                logger.info("工商银行  taskKey: {} 卡片信息：此借记卡账号包含信用卡", context.get(LUA_TASK_KEY));
                continue;
            }
        }
        return flag;
    }catch (e){
        logger.error("{},检查卡列表页面是否包含信用卡出现异常:{}",context.get(LUA_TASK_KEY),e);
    }

}

function crawl() {
    logger.info("工商银行 taskKey： {} 首页信息：节点信息-开始借记卡抓取", context.get(LUA_TASK_KEY));
    var cardListHtml = context.get("cardListHtml");
    try {
        var flag = debitCrawl(cardListHtml);
        context.put("debit_data", debitlist);

    } catch (e) {
        var errorFlag = checkErrorHtml();
        logger.info("{},检查客户指令方法返回的是：{}",context.get(LUA_TASK_KEY),errorFlag);
        if (errorFlag) {
            throw new BankException(BankConstants.BACR_99602_10, "根据客户指令，本次登陆强行退出");
        } else {
            logger.error("工商银行 taskKey:{} crawl 方法中出现异常:",context.get(LUA_TASK_KEY),e);
            statCaughtException(context, e);

        }
    }

　　try{
      var flags = checkIfContainsCreditCards(cardListHtml);
      if (flags) {
          logger.info("工商银行 taskKey： {}，开始信用卡抓取", context.get(LUA_TASK_KEY));
          creditCrawl();
          context.put("credit_data", creditlist);
      }
    }catch (e){
      var errorFlag = checkErrorHtml();
      logger.info("{},检查客户指令方法返回的是：{}",context.get(LUA_TASK_KEY),errorFlag);
      if (errorFlag) {
          throw new BankException(BankConstants.BACR_99602_10,
              "根据客户指令，本次登陆强行退出");
      } else {
          logger.error("工商银行 taskKey:{} crawl 方法中出现异常：",context.get(LUA_TASK_KEY),e);
          statCaughtException(context, e);
      }
   }

}

function checkHtmlthrow(html){
    storeDataToFile(context, html, "checkHtmlThrowSucess.html");
    context.put("checkSuccessFulQuit",html);
    if( html.contains("根据客户指令，本次登陆强行退出") || html.contains("您已经成功退出")){
        throw new BankException(BankConstants.BACR_99602_10, "根据客户指令，本次登陆强行退出");
    }else{
        return html;
    }
}

function creditCrawl() {
    var menuHtml = context.get("accframeHtml");
    var accListMap = new HashMap();
    paraseParamsBills(menuHtml, accListMap);

    var accHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCPERBANKLocationServiceServlet", accListMap));
    storeDataToFile(context, accHtml, "accHtmlG.html")

    var accListHtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn/icbc/newperbank/card/card_myCardList.jsp?dse_sessionId=" + accListMap.get("dse_sessionId")));
    storeDataToFile(context, accListHtml, "accListHtmlG.html")

    if (accListHtml.contains("无法显示此页")) {
        throw new BankException(BankConstants.BALO_99601_10, "代理IP异常");
    } else if (accListHtml.contains("您的预留验证信息为空，请继续设定")) {
        throw new BankException(BankConstants.BALO_22106_10,"您需要完善登录信息,请先到官网进行登录");
    } else if (accListHtml.contains("请您修改网上银行的登录密码")) {
        throw new BankException(BankConstants.BALO_22004_10,"您登录密码已超过六个月未修改，为了您网银的安全使用，请修改登录密码");
    } else {

        var doc = Jsoup.parse(accListHtml);
        var titles = doc.getElementsByTag("title").get(0);
        var title = titles.text();
        if (title.contains("申请办卡")) {
            logger.info("工商银行 taskKey: {} 首页信息：节点信息-用户未注册", context.get(LUA_TASK_KEY));
            return;
        }
    }

    var doc = Jsoup.parse(accListHtml);
    var kabaos = doc.select("[class='kabao-main-item']");

    if(kabaos.size() == 0){
        logger.error("工商银行 taskKey:{} creditCrawl() 方法中kabaos.size() == 0 请检查！",context.get(LUA_TASK_KEY));
    }
    for (var j = 0; j < kabaos.size(); j++) {
        var map = new HashMap();
        // 声明存储对象
        var creditCardAllData = new CreditCardAllData();
        // 声明存储金额列表
        var deposits = new ArrayList();
        // 声明账单列表
        var bills = new ArrayList();
        creditCardAllData.setBills(bills);
        creditCardAllData.setDeposits(deposits);
        var li = kabaos.get(j).attr("id");
        var kabaoElt = kabaos.get(j);
        var liTxt = kabaoElt.getElementsByTag("li").get(1).text();
        if (!liTxt.equals("对账单")) {
            logger.info("工商银行 taskKey:{} 卡包中第【{}】张卡解析时无“对账单”停止解析本张卡",context.get(LUA_TASK_KEY),j+1);
            continue;
        }
        try {
            var cardfull = kabaos.get(j).select("[class='cardNumberDivide card-number']").get(0).text();
            var card_num = cardfull.substring(cardfull.length() - 4, cardfull.length());
            creditCardAllData.setCardNum(card_num);
        } catch (e) {
            logger.error("工商银行 taskKey：{} 卡包中第【{}】张卡解析时卡号未获取到",context.get(LUA_TASK_KEY),j+1);
        }
        // 获取取现额度
        var maps = parseBalanceParamsG(j, kabaos, cardfull, accListMap);
        if (maps != null) {
            var balance = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/AsynGetDataServlet", maps));
            logger.error("工商银行 taskKey: {} 基本信息-解析：信用额度：{}", context.get(LUA_TASK_KEY), balance);
            getCreditCardBalanceSuccsedGsG(balance, maps, creditCardAllData);
        } else {
            creditCardAllData.setCreditLimit(null);
            creditCardAllData.setBalance(null);
        }

        var userMap = new HashMap();
        paraseAccParams(accListHtml, userMap, li);

        var userHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", userMap));

        if (userHtml.equals("no")) {
            logger.info("工商银行 taskKey: {} 基本信息：节点信息：{} ", context.get(LUA_TASK_KEY),userHtml);
        } else {
            storeDataToFile(context, userHtml, j + "_user_1G.html");
            if (userHtml.contains("您的卡片尚未启用")) {
                logger.info("工商银行 taskKey： {} 首页信息：节点信息-您的卡片尚未启用", context.get(LUA_TASK_KEY));
                continue;
            }

            parseUserData(creditCardAllData, userHtml, map);


            var openMap = new HashMap();
            parseOpenHtmlG(userHtml, openMap);
            var openHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/AsynGetDataServlet", openMap));
            storeDataToFile(context, openHtml, j + "_openbankG.html");
            getOpenBankG(creditCardAllData, openHtml);

        }

        // 对账单
        var myBillHtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn/icbc/newperbank/card/card_myBill_index.jsp?dse_sessionId=" + accListMap.get("dse_sessionId")));
        storeDataToFile(context, myBillHtml, j + "_myBillHtmlG.html");

        var cardListMap = new HashMap();
        paraseParamsList(myBillHtml, cardListMap);

        var cardHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", cardListMap));
        storeDataToFile(context, cardHtml, j + "_cardListHtmlG.html");

        var billsMap = new HashMap();
        // 解析对账单参数

        parseBillsHtml(cardHtml, billsMap, creditCardAllData);

        parseBillData(creditCardAllData, cardHtml);

        var billhtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", billsMap));

        storeDataToFile(context, billhtml, j + "_billTableG.html");
        if (billhtml.contains("无法显示此页")) {
            // 无对账单查询
            continue;
        }

        var billDoc = Jsoup.parse(billhtml);
        var lstlinks = billDoc.getElementsByClass("lstlink");
        var unBillMap = new HashMap();
        unBillParams(billDoc, unBillMap);
        var billMap = new HashMap();

        billParams(billDoc, billMap);

        var mothMap = new HashMap();
        for (var i = lstlinks.size() - 1; i >= 0; i--) {
            paraseBillDetail(lstlinks, i, unBillMap, bills,card_num, billMap, j, creditCardAllData, map,mothMap);
        }

        creditlist.add(creditCardAllData);
    }
    if(creditlist.size() == 0){
        throwBankExceptionByErrorCodeAndCustomMessage(BALO_20304_30,"未获取到卡片信息，请登录官网绑定卡片")
    }
}

function paraseAccParams(accListHtml,userMap, li) {
    try {
        var doc = Jsoup.parse(accListHtml);
        var form3s = doc.select("[name='form3']");
        var form3 = form3s.get(0);
        var dse_sessionId = paraseParams(form3, "dse_sessionId");
        var dse_applicationId = this.paraseParams(form3, "dse_applicationId");
        var dse_operationName = this.paraseParams(form3, "dse_operationName");
        var dse_pageId = paraseParams(form3, "dse_pageId");
        var CardNum = paraseParams(form3, "CardNum");
        var cardArea = paraseParams(form3, "cardArea");
        var tranFlag = paraseParams(form3, "tranFlag");
        var doFlag = paraseParams(form3, "doFlag");
        var currLen = paraseParams(form3, "currLen");
        var cardRegMode = paraseParams(form3, "cardRegMode");
        var cardType = paraseParams(form3, "cardType");
        var cardFlag = paraseParams(form3, "cardFlag");
        var parsentAcct = paraseParams(form3, "parsentAcct");
        var parsentNum = paraseParams(form3, "parsentNum");
        var isChip = paraseParams(form3, "isChip");
        var isOperNoNet = paraseParams(form3, "isOperNoNet");
        var TipOpenFlagTemp = paraseParams(form3, "TipOpenFlagTemp");
        var vbv = paraseParams(form3, "vbv");
        var cardareacode = paraseParams(form3, "cardareacode");
        var mycardOwnerType = paraseParams(form3, "mycardOwnerType");
        var crebFlag = paraseParams(form3, "crebFlag");
        var skFlag = paraseParams(form3, "skFlag");
        var cardDescs = paraseParams(form3, "cardDescs");

        userMap.put("dse_sessionId", dse_sessionId);
        userMap.put("dse_applicationId", dse_applicationId);
        userMap.put("dse_operationName", dse_operationName);
        userMap.put("dse_pageId", dse_pageId);
        userMap.put("cardArea", cardArea);
        userMap.put("CardNum", CardNum);
        userMap.put("tranFlag", tranFlag);
        userMap.put("doFlag", doFlag);
        userMap.put("currLen", currLen);
        userMap.put("cardRegMode", cardRegMode);
        userMap.put("cardType", cardType);
        userMap.put("cardFlag", cardFlag);
        userMap.put("parsentAcct", parsentAcct);
        userMap.put("parsentNum", parsentNum);
        userMap.put("isChip", isChip);
        userMap.put("isOperNoNet", isOperNoNet);
        userMap.put("TipOpenFlagTemp", TipOpenFlagTemp);
        userMap.put("vbv", vbv);
        userMap.put("cardareacode", cardareacode);
        userMap.put("mycardOwnerType", mycardOwnerType);
        userMap.put("crebFlag", crebFlag);
        userMap.put("skFlag", skFlag);
        userMap.put("cardDescs", cardDescs);

        var onclick = doc.getElementById(li).select("li").get(5).attr("onclick");
        var param = onclick.split("'");
        creditMore_myCardList(param, userMap);
    } catch (e) {
        logger.error("工商银行 taskKey:{} paraseAccParams()方法中出现异常：{}",context.get(LUA_TASK_KEY),e);
    }
}

function creditMore_myCardList(param, userMap) {
    var cardNum = param[1];
    var currLen = param[3];
    var regMode = param[5];
    var cardType = param[7];
    var cardFlag = param[9];
    var parsentAcct = param[11];
    var isChip = param[13];
    var isOperNoNet = param[15];
    var cardareacode = param[17];
    var cardOwnerType = param[19];
    var crebFlag = param[21];
    var skFlag = param[23];
    var cardDescs = param[25];

    userMap.put("CardNum", cardNum);
    var doFlag = "1";
    userMap.put("doFlag", "1");
    var currLen1 = "3";
    userMap.put("currLen", "3");
    userMap.put("cardRegMode", regMode);
    userMap.put("cardType", cardType);
    userMap.put("cardFlag", cardFlag);
    userMap.put("parsentAcct", parsentAcct);
    userMap.put("isChip", isChip);
    userMap.put("isOperNoNet", isOperNoNet);
    userMap.put("mycardOwnerType", cardOwnerType);
    userMap.put("crebFlag", crebFlag);
    userMap.put("skFlag", skFlag);
    userMap.put("cardDescs", cardDescs);
    var vbv = "1";
    if (cardType.equals("1") || cardType.equals("001")
        || cardFlag.equals("1")) {
        userMap.put("vbv", "0");
        vbv = "0";
    } else {
        userMap.put("vbv", "1");
    }
}

function paraseOpen3Params(cardListHtml, openListMap) {
    var doc = Jsoup.parse(cardListHtml);
    var form3s = doc.select("[name='form3']");
    var form3 = form3s.get(0);
    var dse_sessionId = paraseParams(form3, "dse_sessionId");
    var requestTokenid = paraseParams(form3, "requestTokenid");
    var dse_applicationId = this
        .paraseParams(form3, "dse_applicationId");
    var dse_operationName = this
        .paraseParams(form3, "dse_operationName");
    var dse_pageId = paraseParams(form3, "dse_pageId");
    var cardNo = paraseParams(form3, "cardNo");
    var cardType = paraseParams(form3, "cardType");
    var currtypeR = paraseParams(form3, "currtypeR");
    var currtypeF = paraseParams(form3, "currtypeF");
    var currtypeF1 = paraseParams(form3, "currtypeF1");
    var currFlag = paraseParams(form3, "currFlag");
    var cardHolder = paraseParams(form3, "cardHolder");

    openListMap.put("dse_sessionId", dse_sessionId);
    openListMap.put("requestTokenid", requestTokenid);
    openListMap.put("dse_applicationId", dse_applicationId);
    openListMap.put("dse_operationName", dse_operationName);
    openListMap.put("dse_pageId", dse_pageId);
    openListMap.put("cardNo", cardNo);
    openListMap.put("cardType", cardType);
    openListMap.put("currtypeR", currtypeR);
    openListMap.put("currtypeF", currtypeF);
    openListMap.put("currtypeF1", currtypeF1);
    openListMap.put("currFlag", currFlag);
    openListMap.put("cardHolder", cardHolder);

}

/**
 * 解析信用卡的账单需要的参数
 * @param menuHtml
 * @param cardListMap
 */
function paraseParamsList(menuHtml, cardListMap) {
    try {
        var doc = Jsoup.parse(menuHtml);
        var form2s = doc.select("[name='form2']");
        var form2 = form2s.get(0);
        var dse_sessionId = paraseParams(form2, "dse_sessionId");
        var requestTokenid = paraseParams(form2, "requestTokenid");
        var dse_applicationId = this
            .paraseParams(form2, "dse_applicationId");
        var dse_operationName = this
            .paraseParams(form2, "dse_operationName");
        var dse_pageId = paraseParams(form2, "dse_pageId");
        var CardNum = paraseParams(form2, "CardNum");
        var cardArea = paraseParams(form2, "cardArea");
        var doFlag = paraseParams(form2, "doFlag");
        cardListMap.put("dse_sessionId", dse_sessionId);
        cardListMap.put("requestTokenid", requestTokenid);
        cardListMap.put("dse_applicationId", dse_applicationId);
        cardListMap.put("dse_operationName", dse_operationName);
        cardListMap.put("dse_pageId", dse_pageId);
        cardListMap.put("CardNum", CardNum);
        cardListMap.put("cardArea", cardArea);
        cardListMap.put("doFlag", doFlag);
    } catch (e) {
        logger.error("工商银行 taskKey:{} paraseParamsList()方法中出现异常信息：{}",context.get(LUA_TASK_KEY),e);
    }
}

/**
 * 信用卡的参数
 * @param menuHtml
 * @param billMap
 */
function paraseParamsBills(menuHtml, billMap) {
    var doc = Jsoup.parse(menuHtml);
    var topfameFroms = doc.select("[name='topfameFrom']");
    var topfameFrom = topfameFroms.get(0);
    var dse_sessionIds = topfameFrom.select("[name='dse_sessionId']");
    var dse_sessionId = dse_sessionIds.get(0).attr("value");
    var requestChannels = topfameFrom
        .select("[name='requestChannel']");
    var requestChannel = requestChannels.get(0).attr("value");
    var transDatas = topfameFrom.select("[name='transData']");
    var transData = transDatas.get(0).attr("value");
    var zoneNos = topfameFrom.select("[name='zoneNo']");
    var zoneNo = zoneNos.get(0).attr("value");
    var isflots = topfameFrom.select("[name='isflot']");
    var isflot = isflots.get(0).attr("value");
    var Languages = topfameFrom.select("[name='Language']");
    var Language = Languages.get(0).attr("value");
    var serviceIdIntos = topfameFrom.select("[name='serviceIdInto']");
    var serviceIdInto = serviceIdIntos.get(0).attr("value");
    billMap.put("dse_sessionId", dse_sessionId);
    billMap.put("requestChannel", requestChannel);
    billMap.put("transData", transData);
    billMap.put("zoneNo", zoneNo);
    billMap.put("isflot", isflot);
    billMap.put("Language", Language);
    billMap.put("serviceIdInto", serviceIdInto);
    billMap.put("serviceId", "PBL200779");
}

/**
 * 解析信用卡开户行需要的参数
 * @param userHtml
 * @param openMap
 */
function parseOpenHtmlG(userHtml, openMap) {
    var doc = Jsoup.parse(userHtml);
    var form1s = doc.select("[name='form1']");
    var form = form1s.get(0);
    var dse_sessionId = paraseParams(form, "dse_sessionId");
    var CardNum = paraseParams(form, "CardNum");
    openMap.put("acctNum", CardNum);
    openMap.put("cardNum", CardNum);
    openMap.put("fromCredit", "1");
    openMap.put("SessionId", dse_sessionId);
    openMap.put("tranCode", "A00334");
}

/**
 * 解析信用卡的开户行
 * @param creditCardAllData
 * @param openHtml
 */
function getOpenBankG(creditCardAllData,openHtml) {
     try {
         var openMap = JSON.parseObject(openHtml, Map.class);
         var open_bank = openMap.get("netName");
         creditCardAllData.setOpenBank(open_bank);
     }catch (e){
         logger.error("{},信用卡的开户行异常:{]",context.get(Constants.LUA_TASK_KEY),e);
         statCaughtException(context, e);
     }

}

/**
 * 解析帐单
 * @param lstlinks
 * @param i
 * @param unBillMap
 * @param bills
 * @param card_num
 * @param billMap
 * @param j
 * @param creditCardAllData
 * @param map
 * @param mothMap
 */
function paraseBillDetail(lstlinks, i, unBillMap, bills, card_num, billMap, j, creditCardAllData, map, mothMap) {
     try {
         var lstlink = lstlinks.get(i).text();
         var href = lstlinks.get(i).attr("href");
         var hights = href.split("'");
         var startDate = hights[1];
         var endDate = hights[3];
         var billDate = hights[5];
         if (lstlink.contains("未出对账单")) {
             var billAllData = new BillAllData();
             bills.add(billAllData);
             var shopping_sheets = new ArrayList();// 消费记录

             unBillMap.put("Ddate", "");
             unBillMap.put("dse_operationName", "per_AccountQueryCheckbillUnOp");
             unBillMap.put("endDate", endDate);
             unBillMap.put("startDate", startDate);
             var unbillHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", unBillMap));
             storeDataToFile(context, unbillHtml, j + "_unBillDetailG_1.html");
             var t = 1;
             paraseUnBillData(billAllData, unbillHtml, shopping_sheets, creditCardAllData, mothMap, t, bills);

         } else {
             var billAllData = new BillAllData();
             var shopping_sheets = new ArrayList();// 消费记录
             var billHtml = "";
             var dcr = "0";
             if (billMap.get("cardType").equals("001")) {
                 billMap.put("queryType", "0");
             } else if (billMap.get("cardType").equals("007")) {
                 if (dcr == "2")
                     billMap.put("queryType", "5");
                 else
                     billMap.put("queryType", "4");
             } else if (billMap.get("cardType").equals("008")) {
                 billMap.put("queryType", "3");
             }

             if (endDate.equals("1")) {
                 billHtml = checkHtmlthrow(ajax_get("/servlet/ICBCINBSReqServlet?dse_sessionId="
                     + billMap.get("dse_sessionId")
                     + "&requestTokenid="
                     + billMap.get("requestTokenid")
                     + "&cardNo="
                     + billMap.get("cardNo")
                     + "&cardNum1="
                     + billMap.get("cardNum1")
                     + "&Sel_flag=1&newOldFlag=0&WORKMON="
                     + billDate
                     + "&Tran_flag=1&queryType="
                     + billMap.get("queryType")
                     + "&dse_operationName=per_AccountQueryCheckbillOp"));
                 storeDataToFile(context, billHtml, j + "_billDatasG_" + i + ".html");
             } else {
                 billMap.put("Tran_flag", "0");
                 billMap.put("WORKMON", billDate);
                 billHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", billMap));
                 storeDataToFile(context, billHtml, j + "_billDataG_" + i + ".html");
             }
             paraseBillData(billAllData, billHtml, billDate, mothMap);
             // 解析账单月内容
             var loandata = new HashMap();
             billHtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn/icbc/newperbank/account/account_query_checkbill_loan_detail_index.jsp?dse_sessionId="
                 + billMap.get("dse_sessionId")
                 + "&requestTokenid="
                 + billMap.get("requestTokenid")
                 + "&cardNo="
                 + billMap.get("cardNo") + ""));
             var num = 1;
             var pageFlag = true;
             var t = 1;
             // 增加汇总分期
             var installments = new ArrayList();
             while (pageFlag) {
                 var loanDoc = Jsoup.parse(billHtml);
                 billPageHtml(loanDoc, loandata, num);
                 billHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", loandata));
                 storeDataToFile(context, billHtml, j + "_billDetailG_" + i + "_" + num + ".html");
                 pageFlag = parsePageData(billAllData, billHtml, num,
                     shopping_sheets, card_num, loandata, t);
                 num = num + 1;
             }
             paraseInstallment(shopping_sheets, installments);

             billAllData.setInstallments(installments);
             billAllData.setShoppingSheets(shopping_sheets);
             bills.add(billAllData);
         }
     }catch (e){
         logger.error("{},信用卡解析帐单异常:{}",context.get(Constants.LUA_TASK_KEY),e);
     }


}

function paraseInstallment(shopping_sheets, installments) {
    //shopping_sheets  集合的顺序
    logger.info("{},分期shopping_sheets:{}",context.get(LUA_TASK_KEY),shopping_sheets.toString());
    // for each(var expense in shopping_sheets){
    for(var i = 0; i < shopping_sheets.size(); i ++){
        var trans_addr = shopping_sheets.get(i).getTransAddr();
        var desciption =  shopping_sheets.get(i).getDescription();
        if (desciption.contains("分期付款到期扣收")|| desciption.contains("电话银行") || (trans_addr.contains("汇总分期") && !desciption.contains("手续费"))  || desciption.equals("账单分期")) {
            try {
                var  installment = new Installment();
                if(desciption.equals("账单分期")){
                    installment.setCurrentMonth(1);
                }else{

                    var month = RegexUtils.GetText(trans_addr, "\\d{1,2}\\/\\d{1,2}[期]");
                    month = month.replaceAll("期", "");
                    var total = month.split("/");
                    var total_month = Integer.parseInt(total[1]);
                    var current_month = Integer.parseInt(total[0]);
                    installment.setTotalMonth(total_month);
                    installment.setCurrentMonth(current_month);
                }
                installment.setAmountMoney(shopping_sheets.get(i).getAmountMoney());
                installment.setInstallmentDesc(shopping_sheets.get(i).getDescription());
                installment.setCurrencyType("CNY");
                installment.setInstallmentType("CONSUME");
                installment.setPostDate(shopping_sheets.get(i).getPostDate());
                installment.setTransDate(shopping_sheets.get(i).getTransDate());
                installment.setBillId(UUID.randomUUID().toString());
                installment.setShoppingsheetId(UUID.randomUUID().toString());
                if((i+1) < shopping_sheets.size()){
                   var expense =  shopping_sheets.get(i + 1);
                    var description = expense.getDescription();
                    if(description.contains("手续费")){
                        installment.setHandingFee(expense.getAmountMoney());
                        installment.setHandingfeeDesc(expense.getDescription());
                    }else if(description.equals("分期付款扣款")){
                        installment.setHandingFee(expense.getAmountMoney());
                        installment.setHandingfeeDesc(expense.getDescription());
                         var totalMonth = (shopping_sheets.get(i).getAmountMoney()).intValue() % (expense.getAmountMoney()).intValue();
                        if(totalMonth == 0){
                               var  total =  (shopping_sheets.get(i).getAmountMoney()).intValue() / (expense.getAmountMoney()).intValue();
                                     if(total < 0){
                                         total = - total ;
                                     }
                              installment.setTotalMonth(total);
                        }else if(totalMonth < 0){
                          var   totalMonth = - ((shopping_sheets.get(i).getAmountMoney()).intValue() / (expense.getAmountMoney()).intValue());
                                totalMonth = totalMonth + 1;
                                installment.setTotalMonth(totalMonth);
                        }else {
                          var   totalMonth = (shopping_sheets.get(i).getAmountMoney()).intValue() / (expense.getAmountMoney()).intValue();
                            totalMonth = totalMonth + 1;
                            installment.setTotalMonth(totalMonth);
                        }


                    }
                }
                if((i+1) == shopping_sheets.size()){
                    var expense =  shopping_sheets.get(i);
                    var description = expense.getDescription();
                    if(description.contains("手续费")){
                        installment.setHandingFee(expense.getAmountMoney());
                        installment.setHandingfeeDesc(expense.getDescription());
                    }
                }
                installments.add(installment);
            } catch (e) {
                logger.error("工商银行 taskKey:{} 描述为：{} 的expense 在转化为分期对象时出错：{}",context.get(LUA_TASK_KEY),expense.getDescription(),e);
            }
        }
    }

}



function parsePageData(billAllData, billHtml, i, shopping_sheets, currency, loandata, t) {
    var doc = Jsoup.parse(billHtml);
    var normaltbs = doc.select("[class='normaltbl p3table']");
    var normaltbls = normaltbs.select("[class='normaltbl']");
    var normaltbl = normaltbls.get(0);
    var trs = normaltbl.select("tr");

    var normaltbz = normaltbs.get(0);
    var hrefsz = normaltbz.getElementsByTag("a");
    var num = 0;
    if (hrefsz.size() == 0) {
        num = trs.size();
    } else {
        num = trs.size() - 1;
    }
    for (var j = 2; j < num; j++) {
        var expense = new Expense();
        var tr = trs.get(j);
        var tds = tr.select("td");

        var cardNo = tds.get(0).text();
        var trans_date = tds.get(1).text();
        var post_date = tds.get(2).text();
        var category = tds.get(3).text();
        var description = tds.get(4).text();
        var amount_money = tds.get(5).text();
        var des = tds.get(6).text();
        expense.setCardNum(cardNo);
        expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(trans_date + " 00:00:00"));
        expense.setPostDate(yyyy_MM_dd_PARSER.parse(post_date));
        expense.setDescription(category);
        expense.setBalance(null);
        expense.setCurrencyType("CNY");
        expense.setId(UUID.randomUUID().toString());
        expense.setNameOnOppositeCard("");
        expense.setOppositeBank("");
        expense.setOrderIndex(t[0]);
        expense.setRemark("");
        expense.setTransAddr(description);
        expense.setTransChannel("");
        expense.setTransMethod("");
        expense.setBalance(null);
        if (des.contains("支出")) {
            expense.setAmountMoney(getBigDecimalByString(amount_money));
        } else {
            expense.setAmountMoney(getBigDecimalByString(amount_money)
                .negate());
        }
        expense.setCategory(CategoryUtil.getCreditCategory(BankCode.ICBC, category, expense.getAmountMoney().toString()));
        t[0]++;
        shopping_sheets.add(expense);
    }
    var normaltb = normaltbs.get(0);
    var hrefs = normaltb.getElementsByTag("a");
    if (hrefs.size() == 0) {
        return false;
    }
    var href = hrefs.get(0).attr("href");
    var page = hrefs.get(0).text();
    if (page.contains("下一页")) {
        var params = href.split("'");
        var page1 = params[1];
        var page2 = params[3];
        loandata.put("page", page1);
        loandata.put("YBpage", page2);
        return true;
    } else {
        return false;
    }
}

function billPageHtml(loanDoc, loandata, num) {
    var loanForms = loanDoc.select("[name='loanForm']");
    var loanForm = loanForms.get(0);
    var cardNo = paraseParams(loanForm, "cardNo");
    var changeFlag = paraseParams(loanForm, "changeFlag");
    var dse_applicationId = paraseParams(loanForm,"dse_applicationId");
    var dse_operationName = paraseParams(loanForm,"dse_operationName");
    var dse_pageId = paraseParams(loanForm, "dse_pageId");
    var dse_sessionId = paraseParams(loanForm, "dse_sessionId");
    var page = paraseParams(loanForm, "page");
    var requestTokenid = paraseParams(loanForm, "requestTokenid");
    var YBpage = paraseParams(loanForm, "YBpage");
    loandata.put("cardNo", cardNo);
    loandata.put("changeFlag", changeFlag);
    loandata.put("dse_applicationId", dse_applicationId);
    loandata.put("dse_operationName", dse_operationName);
    loandata.put("dse_pageId", dse_pageId);
    loandata.put("dse_sessionId", dse_sessionId);
    loandata.put("requestTokenid", requestTokenid);
    if (num == 1) {
        loandata.put("page", page);
        loandata.put("YBpage", YBpage);
    }
}

function paraseParams(form, element) {
    var elements = form.select("[name='" + element + "']");
    var ele = elements.get(0).attr("value");
    return ele;
}

function paraseBillData(billAllData, billHtml,bill_month, mothMap) {
    var doc = Jsoup.parse(billHtml);
    var month = new StringBuffer(bill_month);
    month.insert(4, "-");
    var tranData = doc.getElementById("主交易区");
    var normaltbls = tranData.select("[class='normaltbl p3table']");
    var normaltb3 = normaltbls.get(3);
    var trs3 = normaltb3.select("tr");
    var credit_limit = null;
    var min_payment = null;
    var new_balance = null;
    if (trs3.size() != 1) {
        var tds3 = trs3.get(1).select("td");
        credit_limit = tds3.get(4).text();
        min_payment = tds3.get(3).text();
        new_balance = tds3.get(2).text();
    }

    var normaltbl4 = normaltbls.get(4);
    var trs4 = normaltbl4.select("tr");
    var last_balance = trs4.get(4).select("td").get(1).text();
    var last_payment = trs4.get(4).select("td").get(2).text();
    var new_charges2 = trs4.get(4).select("td").get(3).text();
    var new_charges = trs4.get(4).select("td").get(3).text();

    billAllData.setNewCharges(getBigDecimalByString(new_charges));

    /*
     * BigDecimal new_charges1s = getBigDecimalByString(new_charges1);
     * BigDecimal new_charges2s = getBigDecimalByString(new_charges2);
     * double new_charges =
     * new_charges2s.subtract(new_charges1s).doubleValue();
     */

    var normaltb1 = normaltbls.get(1);
    var trs1 = normaltb1.select("tr");
    var tds1 = trs1.get(0).select("td");
    var payment_due_date = tds1.get(2).text().replaceAll("年|月", "-").replaceAll("日| ", "").trim();
    var lastPayment =   doc.select("tr.p3border:nth-child(3) > td:nth-child(3) > div:nth-child(1)").text().replaceAll("/RMB","").replaceAll(",","");
       logger.info("{},上期还款金额:{}",context.get(LUA_TASK_KEY),lastPayment);
    var normaltblls = tranData.select("[class='normaltbl']");
    var normaltbll = normaltblls.get(4);
    if (normaltbll.text().contains("尊敬的客户，为确保您还款准确")) {
        normaltbll = normaltblls.get(5);
        logger.info("");
    }
    var bs = normaltbll.select("b");
    var bill_date = bs.get(1).text();
    bill_date = RegexUtils.GetText(bill_date, "\\d{4}年\\d{2}月\\d{2}").replaceAll("年|月", "-");
    billAllData.setBankName("工商银行");
    billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(bill_date));
    billAllData.setBillId(UUID.randomUUID().toString());
    billAllData.setBillMonth(month.toString());
    mothMap.put(month.toString(), month.toString());
    billAllData.setBillType("DONE");
    billAllData.setCashLimit(null);
    billAllData.setInterest(null);
    billAllData.setCreditLimit(getBigDecimalByString(credit_limit));
    if (last_balance.contains("-")) {
        billAllData.setLastBalance(getBigDecimalByString(last_balance
            .replaceAll("-", "")));
    } else {
        billAllData.setLastBalance(getBigDecimalByString(last_balance)
            .negate());
    }

    billAllData.setLastPayment(new BigDecimal("-" + lastPayment));

    billAllData.setMinPayment(getBigDecimalByString(min_payment));
    billAllData.setNewBalance(getBigDecimalByString(new_balance));
    /*
     * DecimalFormat df=new DecimalFormat(".##"); String
     * st=df.format(new_charges); billAllData.setNewCharges(new
     * BigDecimal(st));
     */

    billAllData.setPaymentDueDate(yyyy_MM_dd_PARSER.parse(payment_due_date));
    billAllData.setUsdCashLimit(null);
    billAllData.setUsdNewCharges(null);
    billAllData.setUsdCreditLimit(null);
    billAllData.setUsdInterest(null);
    billAllData.setUsdLastBalance(null);
    billAllData.setUsdLastPayment(null);
    billAllData.setUsdMinPayment(null);
    billAllData.setUsdNewBalance(null);
    billAllData.setUsdNewCharges(null);
}

function paraseUnBillData(billAllData, unbillHtml, shopping_sheets, creditCardAllData, mothMap, t, bills) {
    var doc = Jsoup.parse(unbillHtml);
    var text = doc.select("#主交易区 > tbody > tr > td > table > tbody > tr > td > table.lst > tbody > tr:nth-child(3) > td:nth-child(5)").text();
    var flag = true;
    if (text.contains("--无交易--")) {
        flag = false;
    }
    var lsts = doc.select("[class='lst']");
    var trs = lsts.select("tr");
    var normaltbls = doc.select("[class='normaltbl']");
    var normaltbl = normaltbls.get(1);
    var trls = normaltbl.select("tr");
    var trl1 = trls.get(1).text();
    var bill_date = RegexUtils.GetText(trl1, "\\d{4}年\\d{2}月\\d{2}").replaceAll("年|月", "-");

    var d = yyyy_MM_dd_FORMAT.parse(bill_date);
    var rightNow = Calendar.getInstance();
    rightNow.setTime(d);
    rightNow.add(Calendar.MONTH, 1);
    rightNow.add(Calendar.DAY_OF_YEAR, -1);
    var months = rightNow.getTime();
    bill_date = yyyy_MM_dd_FORMAT.format(months);
    var month = bill_date.substring(0, 7);
    // var payment_due_date = "";
    billAllData.setBankName("工商银行");
    billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(bill_date));
    billAllData.setBillId(UUID.randomUUID().toString());
    billAllData.setBillMonth(month);
    mothMap.put(month, month);
    billAllData.setBillType("UNDONE");
    billAllData.setCashLimit(null);
    billAllData.setCreditLimit(creditCardAllData.getCreditLimit());
    billAllData.setLastBalance(null);
    billAllData.setLastPayment(null);
    billAllData.setMinPayment(null);
    // billAllData.setNewCharges(null);
    // billAllData.setPaymentDueDate(yyyy_MM_dd_PARSER.parse(payment_due_date));
    billAllData.setUsdCashLimit(null);
    billAllData.setUsdNewCharges(null);
    billAllData.setUsdCreditLimit(null);
    billAllData.setUsdInterest(null);
    billAllData.setUsdLastBalance(null);
    billAllData.setUsdLastPayment(null);
    billAllData.setUsdMinPayment(null);
    billAllData.setUsdNewBalance(null);
    billAllData.setUsdNewCharges(null);
    billAllData.setInterest(null);
    if (flag) {
        for (var i = 2; i < trs.size() - 1; i++) {
            var expense = new Expense();
            try {
                var tr = trs.get(i);
                var tds = tr.select("td");
                var amount_money = tds.get(6).text();
                if (amount_money.equals("0.00/RMB")) {
                    amount_money = tds.get(7).text();
                    expense.setAmountMoney(getBigDecimalByString(amount_money));
                } else {
                    expense.setAmountMoney(getBigDecimalByString(amount_money)
                        .negate());
                }
                var trans_date = tds.get(0).text();
                var card_num = tds.get(2).text();
                var category = tds.get(3).text();
                var post_date = tds.get(1).text();
                var description = tds.get(4).text();

                expense.setCardNum(card_num);
                expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(trans_date + " 00:00:00"));
                expense.setPostDate(yyyy_MM_dd_PARSER.parse(post_date));
                expense.setDescription(category);
                expense.setBalance(null);
                expense.setCurrencyType("CNY");
                expense.setId(UUID.randomUUID().toString());
                expense.setNameOnOppositeCard("");
                expense.setOppositeBank("");
                expense.setOrderIndex(t[0]);
                expense.setRemark("");
                expense.setTransAddr(description);
                expense.setTransChannel("");
                expense.setTransMethod("");
                expense.setRemark("");
                expense.setCardNum(card_num);
                expense.setCategory(CategoryUtil.getCreditCategory(BankCode.ICBC, category, expense.getAmountMoney().toString()));
            } catch (e) {
                logger.error("工商银行 taskKey:{} 未出账单详情中 trs.size() = {} 该条详情解析出错：{}",context.get(LUA_TASK_KEY),trs.size(),e);
            }
            shopping_sheets.add(expense);
            t[0]++;
        }

        // 增加汇总分期
        var installments = new ArrayList();
        paraseInstallment(shopping_sheets, installments);
        billAllData.setInstallments(installments);
        billAllData.setShoppingSheets(shopping_sheets);
        var tr = trs.get(trs.size() - 1);
        var tds = tr.select("td");
        var deposit = tds.get(1).text();
        var expenditure = tds.get(2).text();
        var new_charges1s = getBigDecimalByString(deposit);
        var new_charges2s = getBigDecimalByString(expenditure);
        var total = new_charges2s.subtract(new_charges1s).doubleValue();
        var df = new DecimalFormat(".##");
        var st = df.format(new_charges1s);
        billAllData.setNewBalance(new BigDecimal(total));
        billAllData.setNewCharges(new_charges2s);
        rightNow.setTime(months);
        rightNow.add(Calendar.MONTH, -1);
        var currdate = rightNow.getTime();
        var currmoth = yyyy_MM_dd_FORMAT.format(currdate);
        currmoth = currmoth.substring(0, 7);
        for each(var billData in bills)
        {
            if (currmoth.equals(billData.getBillMonth())) {
                var new_balance = billAllData.getNewBalance();
                if(null == new_balance || 0 == new_balance){
                    new_balance = new BigDecimal("0");
                }
                var new_balance1 = billData.getNewBalance();
                if(null == new_balance1 || 0 == new_balance1){
                    new_balance1 = new BigDecimal("0");
                }
                var currBalance = new_balance.add(new_balance1);
                billAllData.setNewBalance(currBalance);
                billAllData.setLastBalance(billData.getNewBalance());
            }
        }
    } else {
        var installments = new ArrayList();
        billAllData.setInstallments(installments);
        billAllData.setShoppingSheets(shopping_sheets);
        billAllData.setNewBalance(null);
        billAllData.setLastBalance(null);
    }

}

function billParams(billDoc, billMap) {
    var queryForms = billDoc.select("[name='queryForm']");
    var queryForm = queryForms.get(0);
    var acctIndex = paraseParams(queryForm, "acctIndex");
    var cardNo = paraseParams(queryForm, "cardNo");
    var cardNum1 = paraseParams(queryForm, "cardNum1");
    var cardType = paraseParams(queryForm, "cardType");
    var changeFlag = paraseParams(queryForm, "changeFlag");
    var currFlag = paraseParams(queryForm, "currFlag");
    var currtypeF = paraseParams(queryForm, "currtypeF");
    var currtypeR = paraseParams(queryForm, "currtypeR");
    var dcrFlag = paraseParams(queryForm, "dcrFlag");
    var dse_applicationId = paraseParams(queryForm,
        "dse_applicationId");
    var dse_operationName = paraseParams(queryForm,
        "dse_operationName");
    var dse_pageId = paraseParams(queryForm, "dse_pageId");
    var dse_sessionId = paraseParams(queryForm, "dse_sessionId");
    var interCurrType = paraseParams(queryForm, "interCurrType");
    var newOldFlag = paraseParams(queryForm, "newOldFlag");
    var queryType = paraseParams(queryForm, "queryType");
    var requestTokenid = paraseParams(queryForm, "requestTokenid");
    var Sel_flag = paraseParams(queryForm, "Sel_flag");
    var Tran_flag = paraseParams(queryForm, "Tran_flag");
    var WORKMON = paraseParams(queryForm, "WORKMON");
    billMap.put("acctIndex", acctIndex);
    billMap.put("cardNo", cardNo);
    billMap.put("cardNum1", cardNum1);
    billMap.put("cardType", cardType);
    billMap.put("changeFlag", changeFlag);
    billMap.put("currFlag", currFlag);
    billMap.put("currtypeF", currtypeF);
    billMap.put("currtypeR", currtypeR);
    billMap.put("dcrFlag", dcrFlag);
    billMap.put("dse_applicationId", dse_applicationId);
    billMap.put("dse_operationName", dse_operationName);
    billMap.put("dse_pageId", dse_pageId);
    billMap.put("dse_sessionId", dse_sessionId);
    billMap.put("interCurrType", interCurrType);
    billMap.put("newOldFlag", newOldFlag);
    billMap.put("queryType", queryType);
    billMap.put("requestTokenid", requestTokenid);
    billMap.put("Sel_flag", Sel_flag);
    billMap.put("Tran_flag", Tran_flag);
    billMap.put("WORKMON", WORKMON);
}

/**
 * 信用卡的持卡人
 * @param creditCardAllData
 * @param billshtml
 */
function parseBillData(creditCardAllData, billshtml) {
     try{
         var docs = Jsoup.parse(billshtml);
         var lsts = docs.select("[class='lst']");
         var tbodys = lsts.get(0).select("tbody");
         var trs = tbodys.get(0).select("tr");
         var tds = trs.get(1).select("td");
         var name_on_card = tds.get(3).text();
         creditCardAllData.setNameOnCard(name_on_card);
     }catch (e){
         logger.error("{},信用卡持卡人异常:{}",context.get(Constants.LUA_TASK_KEY),e);
     }

}

function unBillParams(billDoc, unBillMap) {
    try {
        var queryUnForms = billDoc.select("[name='queryUnForm']");
        var queryUnForm = queryUnForms.get(0);
        var requestTokenid = this
            .paraseParams(queryUnForm, "requestTokenid");
        var dse_applicationId = paraseParams(queryUnForm,
            "dse_applicationId");
        var dse_pageId = paraseParams(queryUnForm, "dse_pageId");
        var dse_sessionId = paraseParams(queryUnForm, "dse_sessionId");
        var cardType = paraseParams(queryUnForm, "cardType");
        var cardNo = paraseParams(queryUnForm, "cardNo");
        unBillMap.put("requestTokenid", requestTokenid);
        unBillMap.put("dse_applicationId", dse_applicationId);
        unBillMap.put("dse_pageId", dse_pageId);
        unBillMap.put("dse_sessionId", dse_sessionId);
        unBillMap.put("cardType", cardType);
        unBillMap.put("cardNo", cardNo);
    } catch (e) {
        logger.info("工商银行 taskKey:{} unBillParams()方法中出现异常信息:{}",context.get(LUA_TASK_KEY),e);
    }

}

/**
 * 解析信用卡的账单
 * @param billshtml
 * @param map
 * @param creditCardAllData
 */
function parseBillsHtml(billshtml, map, creditCardAllData) {
    try{
        var billsDoc = Jsoup.parse(billshtml);
        var lst = billsDoc.select("[class='lst']");
        var trs = lst.select("tr");
        for (var i = 1; i < trs.size(); i++) {
            var tdl = trs.get(i).select("[class='cardNumberDivide']")
                .get(0);
            var cardFull = tdl.text().replaceAll(" ", "");
            var cardF = creditCardAllData.getFullCardNum();
            if (cardFull.contains(cardF)) {
                var hightbtns = trs.get(i).select("[class='link']");
                // 获取对账单参数
                var hightbtn = hightbtns.get(0).attr("href");
                var params = hightbtn.split("'");
                var cardNum = params[1];
                var cardType = params[3];
                var currTypeR = params[5];
                var currTypeF = params[7];
                var currFlag = params[9];
                map.put("cardNo", cardNum);
                map.put("cardType", cardType);
                map.put("currtypeR", currTypeR);
                map.put("currtypeF", currTypeF);
                map.put("currtypeF1", currTypeF);
                map.put("currFlag", currFlag);
            } else {
                logger.error("任务"
                    + context.get(
                        LUA_TASK_KEY) + "对账单信息：参数信息-无该卡号对账单");
            }
        }
        var form3s = billsDoc.select("[name='form3']");
        var form3 = form3s.get(0);
        var requestTokenid = paraseParams(form3, "requestTokenid");
        var dse_applicationId = this
            .paraseParams(form3, "dse_applicationId");
        var dse_pageId = paraseParams(form3, "dse_pageId");
        var dse_sessionId = paraseParams(form3, "dse_sessionId");
        var dse_operationName = this
            .paraseParams(form3, "dse_operationName");
        var cardHolder = paraseParams(form3, "cardHolder");
        map.put("requestTokenid", requestTokenid);
        map.put("dse_applicationId", dse_applicationId);
        map.put("dse_pageId", dse_pageId);
        map.put("dse_sessionId", dse_sessionId);
        map.put("dse_operationName", dse_operationName);
        map.put("cardHolder", cardHolder);
    }catch (e){
        logger.error("{},信用卡的对账单异常:{}",context.get(Constants.LUA_TASK_KEY),e);
    }

}

/**
 * 信用卡的基本信息
 * @param creditCardAllData
 * @param userHtml
 * @param map
 */
function parseUserData(creditCardAllData,userHtml, map) {
     try{
         // 确认数据
         var doc = Jsoup.parse(userHtml);
         var lsts = doc.select("[class='lst']");
         var tbody = lsts.select("tbody").get(1);
         var trs = tbody.select("tr");
         // BigDecimal credit_limit1 = new BigDecimal(0);
         for (var i = 0; i < trs.size(); i++) {
             var tr = trs.get(i);
             /*
              * if (tr.text().contains("当前余额")) { if
              * (trs.get(i).select("td").get(1).text().equals("")) {
              * credit_limit1 = null; } else { credit_limit1 =
              * getBigDecimalByString(trs.get(i) .select("td").get(1).text()); }
              * } else if (tr.text().contains("可用余额")) { var may =
              * trs.get(i).select("td").get(1).text(); String[] mays =
              * may.split("："); var many = mays[1]; BigDecimal credit_limit2 =
              * getBigDecimalByString(many);
              * creditCardAllData.setBalance(credit_limit2); if (credit_limit1 ==
              * null) { creditCardAllData.setCreditLimit(null); } else { double
              * credit_limit = credit_limit2.subtract(credit_limit1)
              * .doubleValue(); DecimalFormat df = new DecimalFormat(".##");
              * var st = df.format(credit_limit);
              * creditCardAllData.setCreditLimit(new BigDecimal(st)); } } else
              */
             if (tr.text().contains("其它信息")) {
                 var open_time = trs.get(i).select("td").get(1).text();
                 open_time = RegexUtils.GetText(open_time,"办卡日期：\\d{4}年\\d{2}月\\d{2}");
                 creditCardAllData.setOpenTime(yyyy_MM_dd_PARSER.parse(open_time.replaceAll("办卡日期：", "").replaceAll("年|月", "-")));
             }
         }

         var cardNumberDivides = doc.select("[class='cardNumberDivide']");
         var full_card_num = cardNumberDivides.get(0).text().replaceAll(" ", "");

         var normaltbls = doc.select("[class='normaltbl']");
         var normaltbl = normaltbls.get(1);
         var repays = normaltbl.select("tr");
         var repay = repays.get(1);
         var rps = repay.select("td");
         var rp = rps.get(1);
         var state = rps.get(0);
         var stat = state.text().replace("账单日 : ", "").replaceAll("日", "");
         var rep = rp.text().replaceAll("还款日 : ", "").replaceAll("年|月", "-").replaceAll("日", "");
         map.put("repay", rep);
         map.put("stat", stat);
         creditCardAllData.setCashBalance(null);
         creditCardAllData.setCashLimit(null);
         creditCardAllData.setFullCardNum(full_card_num);
         creditCardAllData.setBankName("工商银行");
         creditCardAllData.setCardId(UUID.randomUUID().toString());
         creditCardAllData.setCardType("信用卡");
     }catch (e){
         logger.error("{},信用卡的基本信息异常:{}",context.get(Constants.LUA_TASK_KEY),e)
         statCaughtException(context, e);
     }

}

function getCreditCardBalanceSuccsedGsG(balance, maps, creditCardAllData) {
    try {
        var json = JSON.parseObject(balance);
        var rkArrayjson = json.getJSONArray("rk");
        var rk = rkArrayjson.getJSONObject(0);
        var dcrFlag = maps.get("dcrFlag");
        if (dcrFlag == null) {
            dcrFlag = "";
        }
        var drcrFlag = maps.get("drcrFlag");
        if (drcrFlag == null) {
            drcrFlag = "";
        }
        var cardType = maps.get("acctType");
        if (cardType == null) {
            cardType = "";
        }
        var creditBalance = rk.getString("creditBalance");
        if (creditBalance == null) {
            creditCardAllData.setCreditLimit(null);
        } else {
            if (creditBalance.length() > 2) {
                var buffer = new StringBuffer(creditBalance);
                buffer.insert(creditBalance.length() - 2, ".");
                creditCardAllData.setCreditLimit(new BigDecimal(buffer
                    .toString()));
            } else {
                if (creditBalance.length() == 1) {
                    creditBalance = "0.0" + creditBalance;
                    creditCardAllData.setBalance(new BigDecimal(creditBalance));
                } else if (creditBalance.length() == 2) {
                    creditBalance = "0." + creditBalance;
                    creditCardAllData.setBalance(new BigDecimal(creditBalance));
                }
            }
        }
        var downCircleBalance = rk.getString("downCircleBalance");
        if (downCircleBalance == null) {
            creditCardAllData.setBalance(null);
        } else {
            if (downCircleBalance.length() > 2) {
                var buffer = new StringBuffer(downCircleBalance);
                buffer.insert(downCircleBalance.length() - 2, ".");
                creditCardAllData.setBalance(new BigDecimal(buffer.toString()));
            } else {
                if (downCircleBalance.length() == 1) {
                    downCircleBalance = "0.0" + downCircleBalance;
                    creditCardAllData.setBalance(new BigDecimal(
                        downCircleBalance));
                } else if (downCircleBalance.length() == 2) {
                    downCircleBalance = "0." + downCircleBalance;
                    creditCardAllData.setBalance(new BigDecimal(
                        downCircleBalance));
                }
            }
        }
    } catch (e) {
        logger.error("工商银行 taskKey:{} getCreditCardBalanceSuccsedGsG()方法中解析异常：{}",context.get(LUA_TASK_KEY),e);
        statCaughtException(context, e);
    }
}

function parseBalanceParamsG(j, kabaos, cardfull, accListMap) {
    var span_blance = kabaos.get(j).getElementById("span_blance_" + cardfull.replaceAll(" ", ""));
    if (span_blance == null) {
        span_blance = kabaos.get(j).getElementById("span_blance_" + cardfull.replaceAll(" ", "") + "_0");
    }
    if (span_blance == null) {
        return null;
    }
    var is = span_blance.getElementsByTag("i");
    if (is.size() == 0) {
        logger.error("任务" + context.get(LUA_TASK_KEY) + "基本信息：余额参数-null");
        return null;
    }
    var span_i = span_blance.getElementsByTag("i").get(0);
    var onclick = span_i.attr("onclick");
    logger.info("工商银行 taskKey:{} onclick = {}",context.get(LUA_TASK_KEY), onclick);
    var param = onclick.split("'");
    var map = new LinkedHashMap();
    map.put("BalanceLight", param[1]);
    map.put("cardNum", param[3]);
    map.put("acctNum", param[5]);
    map.put("acctType", param[7]);
    map.put("acctCode", param[9]);
    map.put("currType", param[11]);
    map.put("cashSign", param[13]);
    map.put("operatorFlag", param[15]);
    map.put("drcrFlag", param[17]);
    map.put("align", param[19]);
    map.put("skFlag", param[21]);
    map.put("dcrFlag", param[23]);
    if (param.length > 25) {
        map.put("isRepayment", param[25]);
        map.put("areaCode", param[27]);
    }
    map.put("SessionId", accListMap.get("dse_sessionId"));
    var balance_params = get_balance_paramsG(map);
    logger.error("任务" + context.get(LUA_TASK_KEY) + "基本信息：余额参数-" + balance_params);
    return balance_params;
}

function get_balance_paramsG(map) {
    var paramsMap = new HashMap();
    if (map.get("currType") == null || map.get("currType").equals("")) {
        map.put("currType", "001");
    }
    if (map.get("cashSign") == null || map.get("cashSign").equals("")) {
        map.put("cashSign", "0");
    }

    paramsMap.put("SessionId", map.get("SessionId"));
    paramsMap.put("cardNum", map.get("cardNum"));
    paramsMap.put("acctNum", map.get("acctNum"));
    paramsMap.put("acctType", map.get("cardType"));
    paramsMap.put("acctCode", map.get("acctCode"));
    paramsMap.put("cashSign", map.get("cashSign"));
    paramsMap.put("currType", map.get("currType"));
    paramsMap.put("align", map.get("align"));
    paramsMap.put("operatorFlag", map.get("operatorFlag"));
    paramsMap.put("tranflag", "0");
    paramsMap.put("skFlag", map.get("skFlag"));
    paramsMap.put("tranCode", "A00012");
    return paramsMap;
}

/**
 * 借记卡抓取
 * @param debitHtml
 * @returns {boolean}
 */
function debitCrawl(debitHtml) {
    logger.info("工商银行 taskKey： {}，开始借记卡抓取", context.get(LUA_TASK_KEY));
        var accframeHtml = context.get("accframeHtml");
        var accListMap = new HashMap();
        paraseParamsBillsD(accframeHtml, accListMap);
       logger.info(accListMap.get("dse_sessionId"))
        var flag = false;
        var doc = Jsoup.parse(debitHtml);
        var kabaos = doc.select("[class='kabao-main-item kabao-main-item1']");
        for (var j = 0; j < kabaos.size(); j++) {
            var li = kabaos.get(j).attr("id");
            var kabaoElt = kabaos.get(j);
            var liTxt = kabaoElt.getElementsByTag("li").get(0).text();
            if (!liTxt.equals("明细")) {
                continue;
            }
            var cardType = kabaoElt.getElementsByTag("h6").text();
            if (cardType.contains("电子账户") || cardType.contains("中国农业银行")
                || cardType.contains("人民币e卡")) {
                logger.info("工商银行 taskKey: {} 卡片信息：此卡为电子账户", context.get(LUA_TASK_KEY));
                continue;
            }
            if (kabaoElt.text().contains("距离还款日")) {
                flag = true;
                logger.info("工商银行  taskKey: {} 卡片信息：此借记卡账号包含信用卡", context.get(LUA_TASK_KEY));
                continue;
            }

            var cardfull = kabaos.get(j)
                .select("[class='cardNumberDivide card-number']").get(0)
                .attr("cardnumber");
            var card_num = cardfull.substring(cardfull.length() - 4,
                cardfull.length());
            /*
             * var balance = "0"; try { balance =
             * kabaos.get(j).select("[class='active']").get(1) .text(); } catch
             * (Exception e) { logger.error("任务" + (String)
             * context.get(LUA_TASK_KEY) + "账单信息：节点信息-"
             * + e.getMessage(),e); }
             */
            // 声明存储对象
            var creditCardAllData = new CreditCardAllData();
            // 声明存储金额列表
            var deposits = new ArrayList();
            // 声明账单列表
            var bills = new ArrayList();
            creditCardAllData.setBills(bills);
            creditCardAllData.setDeposits(deposits);
            // creditCardAllData.setBalance(getBigDecimalByString(balance));
            // 获取取现额度
            var maps = parseBalanceParams(j, kabaos, cardfull, accListMap);
            var balance = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/AsynGetDataServlet", maps));
            logger.info("工商银行 taskKey: {} 基本信息-解析：信用额度： {}", context.get(LUA_TASK_KEY), balance);
            getCreditCardBalanceSuccsedGs(balance, maps, creditCardAllData);

            // 点击明细
            var li_chick = kabaoElt.getElementsByTag("li").get(0);
            var chickMap = paraseChickparamse(li_chick, accListMap, debitHtml);
            logger.info("工商银行 taskKey: {} 参数为：{}",context.get(LUA_TASK_KEY),chickMap.toString());
            var chickHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCPERBANKLocationServiceServlet", chickMap));
            storeDataToFile(context, chickHtml, j + "chickHtml.html")
            /*var docDetail = Jsoup.parse(chickHtml);
             var src = docDetail.getElementById("content-frame").attr("src");
             var detailUrl = "https://mybank.icbc.com.cn" + src;
             detailUrl = "https://mybank.icbc.com.cn/icbc/newperbank/1.html";
             var h1 = checkHtmlthrow(ajax_get(detailUrl));
             storeDataToFile(context, h1, "h1.html");*/
            var detailMap = new HashMap();
            var detailFlag = paraseDetailMap(chickHtml,detailMap);
            var detailHtml = "";
            if(equals(detailFlag,true)){
                logger.info("工商银行 taskKey: {} ：{}",context.get(LUA_TASK_KEY),"出现新类型");
                /*     detailHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/icbc/newperbank/modify_initmm1.jsp",detailMap));
                 storeDataToFile(context, detailHtml, j + "_newperbank_0.html")*/
            }else{
                detailHtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn"+detailMap.get("params")));
                //    detailHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet",detailMap));
                storeDataToFile(context, detailHtml, j + "_billDetail_0.html")

                    paraseBeginHtml(detailHtml, card_num, j, bills, cardfull, chickHtml);

            }



            // 获取账户信息
            // 封装菜单参数
            storeDataToFile(context, accframeHtml, "menuList.html")
            var menuUserMap = new HashMap();
            var openMap = new HashMap();

            parseMenuUserHtml(accframeHtml, menuUserMap, openMap);

            var menuUserhtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn/icbc/newperbank/account/account_list_regacct.jsp?dse_sessionId=" + menuUserMap.get("dse_sessionId")));
            storeDataToFile(context, menuUserhtml, "menuUser.html")
            // 封装更多选项参数
            var userMap = new HashMap();

            parseUserHtml(menuUserhtml, li, userMap);


            var userHtml = checkHtmlthrow(ajax_get("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet?" + getUrlParamsByMap(userMap)));
            if (userHtml.equals("no")) {
                logger.info("工商银行 taskKey: {} 基本信息：节点信息:{}", context.get(LUA_TASK_KEY), userHtml);
            } else {
                storeDataToFile(context, userHtml, j + "_user_1.html")

                getBasicNeedInfo(creditCardAllData, userHtml, openMap);


                parseOpenHtml(userHtml, openMap);
                var openHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/icbc/newperbank/perbank3/includes/atomService_control.jsp", openMap));
                storeDataToFile(context, openHtml, j + "_openbank_1.html");
                getOpenBank(creditCardAllData, openHtml);

            }

            // 获取活期存款数据
            var menuMap = new HashMap();
            parseMenuHtml(accframeHtml, menuMap);
            var depHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/icbc/newperbank/perbank3/includes/atomService_control.jsp", menuMap));
            storeDataToFile(context, depHtml, j + "_currentDeposits_1.html");

            if (!depHtml.contains("对不起，您未持有该产品")) {
                getDetailBillByDeposit(depHtml, deposits,
                    creditCardAllData, card_num);
            }


            // 获取定期存款数据
            var depositMap = new HashMap();
            parseDepositHtml(accframeHtml, depositMap);
            var depositHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/icbc/newperbank/perbank3/includes/atomService_control.jsp", depositMap));
            storeDataToFile(context, depositHtml, j + "_regularDeposits_1.html");
            logger.info("工商银行 taskKey: {} 储蓄定期信息：抓到了", context.get(LUA_TASK_KEY));

            debitlist.add(creditCardAllData);
        }
       if(debitlist.size() == 0){
          throwBankExceptionByErrorCodeAndCustomMessage(BALO_20304_30,"未获取到卡片信息，请登录官网绑定卡片")
       }
        return flag;


}

/**
 * 借记卡解析详单的参数
 * @param chickHtml
 * @param detailMap
 * @returns {boolean}
 */
function paraseDetailMap(chickHtml,detailMap) {
    try{
        var billsDoc = Jsoup.parse(chickHtml);
        var frame = billsDoc.getElementById("content-frame");
        var modify = frame.attr("src");
        if(modify.contains("/icbc/newperbank/modify_initmm1.jsp")){
            logger.info("工商银行 taskKey: {} 提示信息：{}", context.get(LUA_TASK_KEY),"修改初始密码");
            return true;
        }else if(modify.contains("/icbc/newperbank/modify_custMessage.jsp")){
            logger.info("工商银行 taskKey: {} 提示信息：{}", context.get(LUA_TASK_KEY),"预留验证信息为空");
            return true;
        }
        detailMap.put("params",modify);
        /*var inputs = form1s.get(0).getElementsByTag("input");
         for (var i = 0; i < inputs.size(); i++) {
         var name = inputs.get(i).attr("name");
         if (name.equals("")) {
         continue;
         }
         var value = inputs.get(i).attr("value");
         detailMap.put(name, value);
         }*/
        return false;
    }catch (e){
        logger.error("{},借记卡解析详单需要的参数异常:{}",context.get(Constants.LUA_TASK_KEY),e);
    }

}

/**
 * 借记卡抓取需要的参数
 * @param frameHtml
 * @param billMap
 */
function paraseParamsBillsD(frameHtml, billMap) {
    try{
        var doc = Jsoup.parse(frameHtml);
        var topfameFroms = doc.select("[name='topfameFrom']");
        var topfameFrom = topfameFroms.get(0);
        var dse_sessionIds = topfameFrom.select("[name='dse_sessionId']");
        var dse_sessionId = dse_sessionIds.get(0).attr("value");
        var requestChannels = topfameFrom
            .select("[name='requestChannel']");
        var requestChannel = requestChannels.get(0).attr("value");
        var transDatas = topfameFrom.select("[name='transData']");
        var transData = transDatas.get(0).attr("value");
        var zoneNos = topfameFrom.select("[name='zoneNo']");
        var zoneNo = zoneNos.get(0).attr("value");
        var isflots = topfameFrom.select("[name='isflot']");
        var isflot = isflots.get(0).attr("value");
        var Languages = topfameFrom.select("[name='Language']");
        var Language = Languages.get(0).attr("value");
        var serviceIdIntos = topfameFrom.select("[name='serviceIdInto']");
        var serviceIdInto = serviceIdIntos.get(0).attr("value");
      /*var dse_sessionId =  doc.select("[name='dse_sessionId']").attr("value");
       var  requestChannel = doc.select("[name='requestChannel']").attr("value");
       var  transData = doc.select("[name='transData']").attr("value");
       var  zoneNo = doc.select("[name='zoneNo']").attr("value");
       var  isflot = doc.select("[name='isflot']").attr("value");
       var  Language = doc.select("[name='Language']").attr("value");
       var  serviceIdInto = doc.select("[name='serviceIdInto']").attr("value");*/

        billMap.put("dse_sessionId", dse_sessionId);
        billMap.put("requestChannel", requestChannel);
        billMap.put("transData", transData);
        billMap.put("zoneNo", zoneNo);
        billMap.put("isflot", isflot);
        billMap.put("Language", Language);
        billMap.put("serviceIdInto", serviceIdInto);
        billMap.put("serviceId", "PBL200779");
    }catch (e){
         logger.error("{},借记卡抓取需要的参数异常{}",context.get(LUA_TASK_KEY),e);
    }

}

/**
 * 借记卡需要的参数
 * @param li_chick
 * @param map
 * @param frameHtml
 * @returns {HashMap}
 */
function paraseChickparamse(li_chick, map, frameHtml) {
    try{
        var chickMap = new HashMap();
        var onclick = li_chick.attr("onclick");
        var params = onclick.split("'");
        chickMap.put("serviceId", params[1]);
        chickMap.put("transData", params[3]);
        chickMap.put("dse_sessionId", map.get("dse_sessionId"));
        chickMap.put("requestChannel", map.get("requestChannel"));
        chickMap.put("serviceIdInto", "");
        chickMap.put("zoneNo", "");
        return chickMap;
    }catch (e){
        logger.error("{},借记卡需要的参数异常:{}",context.get(Constants.LUA_TASK_KEY),e);
    }

}

/**
 * 借记卡的定期需要的参数
 * @param menuHtml
 * @param depositMap
 */
function parseDepositHtml(menuHtml, depositMap) {
     try{
         var doc = Jsoup.parse(menuHtml);
         var topfameFroms = doc.select("[name='topfameFrom']");
         var topfameFrom = topfameFroms.get(0);
         var dse_sessionIds = topfameFrom.select("[name='dse_sessionId']");
         var dse_sessionId = dse_sessionIds.get(0).attr("value");
         var requestChannels = topfameFrom
             .select("[name='requestChannel']");
         var requestChannel = requestChannels.get(0).attr("value");
         var transDatas = topfameFrom.select("[name='transData']");
         var transData = transDatas.get(0).attr("value");
         depositMap.put("dse_sessionId", dse_sessionId);
         depositMap.put("requestChannel", requestChannel);
         depositMap.put("transData", transData);
         depositMap.put("serviceId", "PBL20171702");
     }catch (e){
         logger.error("{},借记卡的定期需要的参数异常:{}",context.get(Constants.LUA_TASK_KEY),e);
     }


}

/**
 * 借记卡的活期数据
 * @param depHtml
 * @param deposits
 * @param creditCardAllData
 * @param card_num
 */
function getDetailBillByDeposit(depHtml, deposits, creditCardAllData, card_num) {
      try{
          var deposit = new CreditCardTimeDeposit();
          var doc = Jsoup.parse(depHtml, "utf-8");
          var tables = doc.select("[class='smalllst']");
          if(tables.size() > 0){
              var table = tables.get(0);
              var trs = table.select("tr");
              for (var i = 1; i < trs.size(); i++) {
                  var cardNum = trs.get(i).select("td").get(0).text();
                  if (cardNum.endsWith(card_num)) {
                      var currency_type = trs.get(i).select("td").get(4).text();
                      var deposit_type = "活期存储";
                      var balance = trs.get(i).select("td").get(5).text()
                          .replaceAll(",", "");
                      creditCardAllData.setBalance(getBigDecimalByString(balance));
                      deposit.setBalance(getBigDecimalByString(balance));
                      deposit.setCurrencyType(BizConstants.currencyTypeMappings.get(currency_type));
                      deposit.setDepositDate(null);
                      deposit.setDepositType(deposit_type);
                      deposit.setDueDate(null);
                      deposit.setInterest(null);
                      deposit.setPeriod(new Integer(0));
                      deposit.setPeriodUnit("");
                      deposits.add(deposit);

                  }

              }
          }else{
              logger.error("工商银行 taskKey:{} getDetailBillByDeposit()方法中tables.size()=0",context.get(LUA_TASK_KEY))
          }
      }catch (e){
           logger.error("{},借记卡的活期数据解析异常:{}",context.get(Constants.LUA_TASK_KEY),e);
      }


}

function parseMenuHtml(menuHtml, menuMap) {
    var doc = Jsoup.parse(menuHtml);
    var topfameFroms = doc.select("[name='topfameFrom']");
    var topfameFrom = topfameFroms.get(0);
    var dse_sessionIds = topfameFrom.select("[name='dse_sessionId']");
    var dse_sessionId = dse_sessionIds.get(0).attr("value");
    var requestChannels = topfameFrom
        .select("[name='requestChannel']");
    var requestChannel = requestChannels.get(0).attr("value");
    var transDatas = topfameFrom.select("[name='transData']");
    var transData = transDatas.get(0).attr("value");
    menuMap.put("dse_sessionId", dse_sessionId);
    menuMap.put("requestChannel", requestChannel);
    menuMap.put("transData", transData);
    menuMap.put("serviceId", "PBL20171701");
}

/**
 * 借记卡的开户行
 * @param creditCardAllData
 * @param openHtml
 */
function getOpenBank(creditCardAllData, openHtml) {
    try{
        var doc = Jsoup.parse(openHtml);
        var normaltbls = doc.select("[class='normaltbl']");
        if(normaltbls.size() > 0){
            var normaltbl = normaltbls.get(0);
            var trs = normaltbl.select("tr");
            for (var i = 0; i < trs.size(); i++) {
                var tr = trs.get(i);
                if (tr.text().contains("开户网点")) {
                    var tds = tr.select("td");
                    var td = tds.get(1);
                    creditCardAllData.setOpenBank(td.text().replaceAll(" ", ""));
                }
            }
        }else{
            logger.error("工商银行 taskKey:{} getOpenBank() 方法中 normaltbls.size() = 0 ",context.get(LUA_TASK_KEY))
        }
    }catch (e){
        logger.error("{},借记卡开户行解析异常:{}",context.get(Constants.LUA_TASK_KEY),e);
    }

}

/**
 * 解析借记卡的开户需要的参数
 * @param userHtml
 * @param openMap
 */
function parseOpenHtml(userHtml, openMap) {
     try{
         var doc = Jsoup.parse(userHtml);
         var lsts = doc.select("[class='lst']");
         if(lsts.size() > 0){
             var lst = lsts.get(0);
             var openTrs = lst.select("tr");
             for (var i = 0; i < openTrs.size(); i++) {
                 var openTr = openTrs.get(i);
                 if (openTr.text().contains("开户网点")) {
                     var tds = openTr.select("td");
                     var td = tds.get(1);
                     var a = td.getElementsByTag("a").get(0);
                     var href = a.attr("href");
                     var params = href.split("'");
                     openMap.put("serviceId", params[1]);
                     openMap.put("transData", params[3]);
                 }
             }
         }else{
             logger.info("工商银行 taskKey:{} parseOpenHtml()方法中解析银行卡详情时 lsts.size() = 0 获取失败，请查看！", context.get(LUA_TASK_KEY))
         }
     }catch (e){
         logger.error("{},借记卡的开户行需要的参数异常:{}",context.get(Constants.LUA_TASK_KEY),e);
     }

}

/**
 * 借记卡的基本信息
 * @param creditCardAllData
 * @param userHtml
 * @param openMap
 */
function getBasicNeedInfo(creditCardAllData, userHtml, openMap) {
      try{
          var doc = Jsoup.parse(userHtml, "utf-8");
          var tables = doc.select("[class='normaltbl']");
          var table = tables.get(0);
          var trs = table.select("tr");

          var name_on_card = trs.get(0).select("td").get(2).text();
          var open_time = trs.get(1).select("td").get(6).text();
          open_time = open_time.replace("年", "-").replace("月", "-")
              .replace("日", "");
          var full_card_num = trs.get(0).select("td").get(6).text();
          var card_num = full_card_num.substring(full_card_num.length() - 4,
              (full_card_num.length()));
          var card_type = "借记卡";
          var bank_name = "工商银行";
          creditCardAllData.setBankName(bank_name);
          creditCardAllData.setCardId(UUID.randomUUID().toString());
          creditCardAllData.setCardNum(card_num);
          creditCardAllData.setCardType(card_type);
          creditCardAllData.setCashBalance(null);
          creditCardAllData.setCashLimit(null);
          creditCardAllData.setCreditLimit(null);
          creditCardAllData.setFullCardNum(full_card_num);
          creditCardAllData.setNameOnCard(name_on_card);
          creditCardAllData.setOpenTime(yyyy_MM_dd_PARSER.parse(open_time));
      }catch (e){
          logger.error("{},借记卡的基本信息抓取异常:{}",context.get(Constants.LUA_TASK_KEY),e)
      }


}

/**
 * 借记卡解析帐户信息
 * @param menuUserhtml
 * @param li
 * @param userMap
 */
function parseUserHtml(menuUserhtml, li, userMap) {
     try{
         var doc = Jsoup.parse(menuUserhtml);
         var form2s = doc.select("[name='form2']");
         var form2 = form2s.get(0);
         var dse_sessionIds = form2.select("[name='dse_sessionId']");
         var dse_sessionId = dse_sessionIds.get(0).attr("value");
         var requestTokenids = form2.select("[name='requestTokenid']");
         var requestTokenid = requestTokenids.get(0).attr("value");
         var dse_applicationIds = form2
             .select("[name='dse_applicationId']");
         var dse_applicationId = dse_applicationIds.get(0).attr("value");
         var dse_operationNames = form2
             .select("[name='dse_operationName']");
         var dse_operationName = dse_operationNames.get(0).attr("value");

         userMap.put("dse_sessionId", dse_sessionId);
         // userMap.put("requestTokenid", requestTokenid);
         // userMap.put("dse_applicationId", dse_applicationId);
         userMap.put("dse_operationName", dse_operationName);

         // var kabaos = doc.select("[class='kabao-main-item']");
         if(doc.getElementById(li).select("li").size() > 4){
             var onclick = doc.getElementById(li).select("li").get(5).attr("onclick");
             var param = onclick.split("'");
             userMap.put("menuFlag", param[1]);
             userMap.put("regCardNum", param[3]);
             userMap.put("cardtype", param[5]);
             userMap.put("areaname", param[7]);
             userMap.put("openAreaCode", param[9]);
             userMap.put("regmode", param[11]);
             userMap.put("entranceId", param[13]);
             userMap.put("cardOwnerType", param[15]);
             userMap.put("skFlag", param[17]);
             userMap.put("skNo", param[19]);
             userMap.put("cardDescs", param[21]);
             userMap.put("acctCode", param[23]);
             userMap.put("acctNum", param[25]);
             if (param.length > 27) {
                 userMap.put("ltCardFlag", param[27]);
             } else {
                 userMap.put("ltCardFlag", "undefined");
             }
             var tranFlag = "1";
             if (param[1].equals("3")) {
                 tranFlag = "4";
             } else if (param[1].equals("4")) {
                 tranFlag = "5";
             }
             userMap.put("tranFlag", tranFlag);

         }else{
             logger.error("工商银行 taskKey:{} parseUserHtml()方法中 doc.getElementById(li).select(\"li\").size() <= 4  菜单信息-更多解析异常",context.get(LUA_TASK_KEY));
         }
     }catch (e){
         logger.error("{},借记卡帐户信息抓取异常:{}",context.get(Constants.LUA_TASK_KEY),e);
     }
}

/**
 * 将map转换成url
 *
 * @param map
 * @return
 */
function getUrlParamsByMap(map) {
    if (map == null) {
        return "";
    }
    var sb = new StringBuffer();
    for each(var entry
in
    map.entrySet()
)
    {
        sb.append(entry.getKey() + "=" + entry.getValue());
        sb.append("&");
    }
    var s = sb.toString();
    if (s.endsWith("&")) {
        s = org.apache.commons.lang.StringUtils.substringBeforeLast(s, "&");
    }
    return s;
}

/**
 * 借记卡解析帐户需要准备的参数
 * @param menuHtml
 * @param userMap
 * @param openMap
 */
function parseMenuUserHtml(menuHtml, userMap, openMap) {
    var doc = Jsoup.parse(menuHtml);
    var topfameFroms = doc.select("[name='topfameFrom']");
    var topfameFrom = topfameFroms.get(0);
    var dse_sessionIds = topfameFrom.select("[name='dse_sessionId']");
    var dse_sessionId = dse_sessionIds.get(0).attr("value");
    var requestChannels = topfameFrom
        .select("[name='requestChannel']");
    var requestChannel = requestChannels.get(0).attr("value");
    var transDatas = topfameFrom.select("[name='transData']");
    var transData = transDatas.get(0).attr("value");
    var zoneNos = topfameFrom.select("[name='zoneNo']");
    var zoneNo = zoneNos.get(0).attr("value");
    var isflots = topfameFrom.select("[name='isflot']");
    var isflot = isflots.get(0).attr("value");
    var Languages = topfameFrom.select("[name='Language']");
    var Language = Languages.get(0).attr("value");
    var serviceIdIntos = topfameFrom.select("[name='serviceIdInto']");
    var serviceIdInto = serviceIdIntos.get(0).attr("value");
    userMap.put("dse_sessionId", dse_sessionId);
    userMap.put("requestChannel", requestChannel);
    userMap.put("transData", transData);
    userMap.put("zoneNo", zoneNo);
    userMap.put("isflot", isflot);
    userMap.put("Language", Language);
    userMap.put("serviceIdInto", serviceIdInto);
    userMap.put("serviceId", "PBL201786");

    openMap.put("dse_sessionId", dse_sessionId);
    openMap.put("requestChannel", requestChannel);

}

function paraseHisForm(hisForm) {
    if (hisForm.contains("您没有任何卡可以进行该项交易")) {
        return true;
    } else if (hisForm.contains("灵通卡下挂账户中的通知存款子账户不能查询历史明细")) {
        return true;
    } else if (hisForm.contains("该种香港信用卡不能查询历史明细")) {
        return true;
    } else if (hisForm.contains("日期不能为空")) {
        return true;
    } else if (hisForm.contains("输入的时间格式不对,请重新确认")) {
        return true;
    } else if (hisForm.contains("支持查询的起始日期最早为2012-08-19，请您重新设置")) {
        return true;
    } else if (hisForm.contains("写入快照失败")) {
        return true;
    }
    return false;
}

/**
 * 借记卡消费明细
 * @param beginHtml
 * @param card_num
 * @param j
 * @param bills
 * @param cardfull
 * @param chickHtml
 */
function paraseBeginHtml(beginHtml, card_num, j, bills, cardfull, chickHtml) {
      try{
          var cal = Calendar.getInstance();
          var endDate = yyyy_MM_dd_FORMAT.format(cal.getTime());
          cal.add(Calendar.YEAR, -2);
          var beginDate = yyyy_MM_dd_FORMAT.format(cal.getTime());

          var expList = new ArrayList();
          var doc = Jsoup.parse(beginHtml);
          var hisformMap = new HashMap();
          paraseHisform(beginHtml, hisformMap);
          var csubmitspan = doc.getElementById("csubmitspan");
          var a = csubmitspan.getElementsByTag("a").get(0);
          var href = a.attr("href");
          var params = href.split("'");
          var hisForm = gs_hisform_param(params[1], params[3], params[5],
              params[7], params[9], params[11], params[13], params[15],
              params[17], params[19], params[21], params[23], params[25],
              params[27], params[29], params[31], params[33], params[35],
              params[37], params[39], beginDate, hisformMap, beginHtml,
              cardfull, endDate, chickHtml);
          var flag = paraseHisForm(hisForm);
          if (flag) {
              logger.error("任务" + context.get(LUA_TASK_KEY) + hisForm);
              return;
          }

          var detailHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", hisformMap));
          storeDataToFile(context, detailHtml, j + "_billDetail_1.html")
          var pageFlag = true;
          pageFlag = paraseExpense(expList, detailHtml, card_num);
          var num = 2;
          // Long[] t = {1L};
          var loandata = new HashMap();
          while (pageFlag) {
              paraseDetailHtml(detailHtml, loandata, chickHtml, cardfull);
              detailHtml = checkHtmlthrow(ajax_post("https://mybank.icbc.com.cn/servlet/ICBCINBSReqServlet", loandata));
              storeDataToFile(context, detailHtml, j + "_billDetail_" + num + ".html")
              pageFlag = paraseExpense(expList, detailHtml, card_num);
              num = num + 1;
          }

          // 获取账单列表
          var calendar = Calendar.getInstance();
          for (var i = 0; i <= 12; i++) {
              var year = calendar.get(Calendar.YEAR);
              var month = calendar.get(Calendar.MONTH) + 1; // calendar.get(Calendar.MONTH)返回值得第一个月为0，所以+1。
              month = Integer.parseInt(month);
              var yearMoth = year + "-" + getYearOrDayString(month);
              logger.info("工商银行 taskKey: {} 借记卡账单信息：账单月份:{}", context.get(LUA_TASK_KEY), yearMoth);

              getDetailBillByDateNew(expList, bills, yearMoth, card_num);

              calendar.add(Calendar.MONTH, -1);
          }
      }catch (e){
          logger.error("{},借记卡{}月份,解析异常:{}",context.get(Constants.LUA_TASK_KEY),yearMoth,e);
      }


}

function paraseHisform(beginHtml, hisformMap) {
    try {
        var doc = Jsoup.parse(beginHtml);
        var form1s = doc.select("[name='histForm']");
        if (form1s.size() > 0) {
            var inputs = form1s.get(0).getElementsByTag("input");
            for (var i = 0; i < inputs.size(); i++) {
                var name = inputs.get(i).attr("name");
                if (name.equals("")) {
                    continue;
                }
                var value = inputs.get(i).attr("value");
                hisformMap.put(name, value);
            }
        } else {
            logger.info("工商银行  taskKey:{}  paraseHisform()  方法中 本次请求 form1s.size() = 0 ", context.get(LUA_TASK_KEY))
        }
    } catch (e) {
        logger.error("工商银行  taskKey:{}  paraseHisform()  方法中解析错误：{}", context.get(LUA_TASK_KEY),e);
        statCaughtException(context, e);
    }
}

function gs_hisform_param(form, tranFlag,
                          currName, sessionId, ishere,
                          detailFlagArea, payQueryYear, ishdm,
                          hdmDown, fromHDM, beginFree, pageflag,
                          amtin, amtout, amtin1, amtout1,
                          prepageFlag, curamtin, curamtout,
                          isclear, beginDate, hisformMap,
                          beginHtml, cardfull, endDate, chickHtml) {

    // ishdm是否需要判断超期（超期翻页到免费期时不需判断，送0，其余送1）
    // hdmDown是否超期下载，下载用到，与免费期走不同分支
    // fromHDM是否从缴费页面来的，一般送0，免费期到超期上一页的时候送1，此时不走收费流程
    // beginFree：如开始查询15-24个月免费明细，送1 如15-24个月到超期向上翻页，送2
    // pageflag：仅在切换库时有效，1下翻页 0上翻页
    // prepageFlag:切换库后，总金额计算方式改变，送0，1以外的变量，写死2
    // document.histForm.overFlag.value="0";
    // //上来先把overflag状态置回，否则先查超期再查免费会有问题
    // isclear:重新点击查询按钮时触发，此时需要把begdate1,enddate1什么的置回空
    var account = getAcctSelList(beginHtml, cardfull);
    var accountNo = "0";
    var acc = new HashMap();
    for each(var m
in
    account.entrySet()
)
    {
        accountNo = m.getKey();
        acc = m.getValue();
    }

    if (isHomeCardFuc(checkStringIsNull(acc.get("acctSelList")))) {
        return "";
    }
    var skflag = acc.get("skFlag");
    if (skflag == null || skflag.equals("") || skflag == "undefined") {
        skflag = "0";
    }
    hisformMap.put("SKflag", skflag);
    if (skflag == "1") { // 闪酷
        if (acc.get("acctType").equals("011")) { // 借记卡
            if (hisformMap.get("onoffJJFlag").equals("1")) { // 线下
                hisformMap.put("ACSTYPE", "");
                hisformMap.put("ACAPPNO", "");
            }
        }
    }
    if (skflag == "2") { // SD卡
        hisformMap.put("ACAPPNO", "01");
    }

    var skFlag_tmp; // 201402 SD卡
    hisformMap.put("fromHDM", fromHDM);
    hisformMap.put("ishere", ishere);

    var card_num = "";
    var cardtype2 = "";
    if (isHomeCardFuc(accountNo)) {
        skFlag_tmp = "0";
        card_num = cardfull;
        hisformMap.put("ishomecard", "0");
    } else {
        skFlag_tmp = acc.get("skFlag");
        card_num = cardfull;
        cardtype2 = acc.get("acctType");
        hisformMap.put("ishomecard", "0");
    }
    var cardBinList = getCardBinList(chickHtml);
    var cardtype1 = getcardtype(card_num, cardBinList);

    if (cardtype1.equals("003") && cardtype2.equals("011")) {
        hisformMap.put("isupdate", "1");
    } else {
        hisformMap.put("isupdate", "0");
    }

    var to_date;
    if (account.size() == 0) {
        return "您没有任何卡可以进行该项交易";
    }
    var account1 = getAcctSelList2(
        beginHtml, cardfull);
    var accountNo1 = "0";
    var acc1 = new HashMap();
    for each(var m1
in
    account1.entrySet()
)
    {
        accountNo1 = m1.getKey();
        acc1 = m1.getValue();
    }
    hisformMap.put("acctCode", acc1.get("acctCode"));
    hisformMap.put("acctIndex", accountNo1);
    hisformMap.put("acctNum", acc1.get("acctNum"));
    hisformMap.put("acctSelList", accountNo);
    hisformMap.put("ACSTYPE", "0");
    hisformMap.put("cardNum", acc1.get("cardNum"));
    hisformMap.put("cardType", cardtype1);
    hisformMap.put("acctSelList2", accountNo1);
    hisformMap.put("styFlag", "0");
    if (!isHomeCardFuc(accountNo)) {
        if (acc1.get("acctType") == "003"
            && !(accountNo1 == "no" || accountNo1 == "dr" || accountNo1 == "cr")) {
            if (acc1.get("acctType").equals("08")) {
                return "灵通卡下挂账户中的通知存款子账户不能查询历史明细";
            }
        }
    }

    var account0 = accountNo1;

    var temp = beginDate;
    var temp2 = endDate;
    var temp3 = hisformMap.get("days");
    hisformMap.put("begDate", temp);
    hisformMap.put("endDate", temp2);
    // document.histForm.begDate.value="2011-12-01";
    // document.histForm.endDate.value="2017-12-31";

    hisformMap.put("DRCRF_IN", "0");

    var subObj0 = checkStringIsNull(hisformMap.get("acctIndex"));
    var subObj1 = checkStringIsNull(hisformMap.get("cardNum"));
    var subObj2 = checkStringIsNull(hisformMap.get("acctCode"));
    var subObj3 = checkStringIsNull(hisformMap.get("acctSelList2"));
    var subObj4 = checkStringIsNull(hisformMap.get("Tran_flag"));
    var subObj5 = checkStringIsNull(hisformMap.get("cardType"));
    var subObj6 = checkStringIsNull(hisformMap.get("currTypeName"));
    var subObj7 = checkStringIsNull(hisformMap.get("queryType"));
    var subObj8 = checkStringIsNull(hisformMap.get("cardAlias"));
    var subObj9 = checkStringIsNull(hisformMap.get("acctAlias"));
    var subObj10 = checkStringIsNull(hisformMap.get("currType"));
    var subObj11 = checkStringIsNull(hisformMap.get("styFlag"));
    var subObj12 = checkStringIsNull(hisformMap.get("type"));
    var subObj13 = checkStringIsNull(hisformMap.get("init_flag"));
    var subObj14 = checkStringIsNull(hisformMap.get("Areacode"));
    var subObj16 = checkStringIsNull(hisformMap.get("Begin_pos"));
    var subObj15 = checkStringIsNull(hisformMap.get("pageflag"));
    var subObj17 = checkStringIsNull(hisformMap.get("initDate"));
    var subObj18 = checkStringIsNull(hisformMap.get("initTime"));
    var subObj19 = checkStringIsNull(hisformMap.get("cityFlag"));
    hisformMap.put("ishere", ishere);
    subObj15 = "0";
    subObj16 = "-1";
    subObj13 = "1";
    if (isHomeCardFuc(accountNo)) {
        subObj1 = getHomeCard(accountNo);
        subObj5 = "007";
        subObj8 = "";
    } else {
        subObj1 = checkStringIsNull(acc.get("cardNum"));
        subObj5 = checkStringIsNull(acc.get("acctType"));
        subObj8 = checkStringIsNull(acc.get("cardAlias"));
    }
    subObj6 = currName;
    if (!(subObj3.equals("no") || subObj3.equals("dr") || subObj3
            .equals("cr"))) {
        accountNo = subObj3;
        subObj2 = acc1.get("acctCode");
        hisformMap.put("acctType", acc1.get("acctType"));
        hisformMap.put("acctTypeName", acc1.get("acctType"));
        hisformMap.put("acctNum", acc1.get("acctNum"));
        subObj9 = acc.get("acctAlias");
        if (subObj5.indexOf("A") != -1
            || checkStringIsNull(hisformMap.get("acctType")).indexOf(
                "A") != -1) {
            subObj2 = acc1.get("acctNum");
        }
    } else {
        if (subObj5.equals("003") || subObj5.equals("011")) {
            hisformMap.put("acctType", "01");
            hisformMap.put("acctTypeName", "01");
            subObj2 = "0";
        } else {
            subObj2 = "";
        }
    }
    if (subObj2.equals("000") || subObj2.equals("00000")) {
        hisformMap.put("qaccf", "1");
    } else {
        hisformMap.put("qaccf", "0");
    }
    subObj0 = accountNo;
    if (subObj5.indexOf("A") == -1 && subObj5.indexOf("F") == -1) {
        if (subObj5.equals("011")
            && !(hisformMap.get("acctType").equals("20")
                || hisformMap.get("acctType").equals("21")
                || hisformMap.get("acctType").equals("22")
                || hisformMap.get("acctType").equals("23") || hisformMap
                    .get("acctType").equals("24")))
            subObj7 = "0";
        else if (subObj5.equals("003")
            && !(hisformMap.get("acctType").equals("20")
                || hisformMap.get("acctType").equals("21")
                || hisformMap.get("acctType").equals("22")
                || hisformMap.get("acctType").equals("23") || hisformMap
                    .get("acctType").equals("24")))
            subObj7 = "1";
        else if (hisformMap.get("acctType").equals("20")
            || subObj5.equals("008")
            || hisformMap.get("acctType").equals("21")
            || subObj5.equals("007"))// fuwei new
            subObj7 = "3";
        else if (subObj5.equals("999"))
            subObj7 = "8";
        else
            subObj7 = "2";
    } else if (subObj5.indexOf("A") != -1) {
        subObj7 = "10";
    } else if (subObj5.indexOf("F") != -1) {// queryType为12海外fova
        hisformMap.put("Area", acc.get("areaCode"));
        subObj7 = "12";
    }
    if (subObj5.equals("F10101")) {// FovaAcctType为0海外fova活期
        hisformMap.put("FovaAcctType", "0");
    } else if (subObj5.equals("F10192")) {// 海外fova综合帐户活期
        hisformMap.put("FovaAcctType", "0");
    } else if (subObj5.equals("F80001")) {// 海外信用卡
        hisformMap.put("FovaAcctType", "3");
    } else if (subObj5.indexOf("F") != -1) {// FovaAcctType为2海外fova贷款
        hisformMap.put("FovaAcctType", "2");
    }
    if (subObj3.equals("dr")) {// 11月借贷合一卡 类型 0-全部 1-贷记帐户 2-国际借记帐户
        hisformMap.put("drcrFlag", "2");
    } else if (subObj3.equals("cr")) {
        hisformMap.put("drcrFlag", "1");
    } else {
        hisformMap.put("drcrFlag", "0");
    }
    subObj4 = "0"; // 表示查询
    subObj12 = "browser";
    hisformMap.put("acctIndex", subObj0);
    hisformMap.put("cardNum", subObj1);
    hisformMap.put("acctCode", subObj2);
    hisformMap.put("acctSelList2", subObj3);
    hisformMap.put("Tran_flag", subObj4);
    hisformMap.put("cardType", subObj5);
    hisformMap.put("currTypeName", subObj6);
    hisformMap.put("queryType", subObj7);
    hisformMap.put("cardAlias", subObj8);
    hisformMap.put("acctAlias", subObj9);
    hisformMap.put("currType", subObj10);
    hisformMap.put("styFlag", subObj11);
    hisformMap.put("type", subObj12);
    hisformMap.put("init_flag", subObj13);
    hisformMap.put("Areacode", subObj14);
    hisformMap.put("Begin_pos", subObj16);
    hisformMap.put("pageflag", subObj15);
    hisformMap.put("initDate", subObj17);
    hisformMap.put("initTime", subObj18);
    hisformMap.put("cityFlag", subObj19);
    hisformMap.put("graylink", "0");
    hisformMap.put("YETYPE", "0");
    hisformMap.put("onoffJJFlag", "2");
    return "";
}

function checkStringIsNull(param) {
    if (param == null) {
        return "";
    } else {
        return param;
    }

}

function getHomeCard(value) {
    var temp;
    try {
        temp = value.substring(9, value.length());
    } catch (e) {
        temp = value;
    }
    return temp;
}

function getAcctSelList2(beginHtml, cardfull) {
    var map = new HashMap();
    var acc = new HashMap();
    var acctList = RegexUtils.GetList(beginHtml,
        "acctList.add\\(new Account\\(([^;]*?)\\)");
    for (var i = 0; i < acctList.size(); i++) {
        if (acctList.get(i).contains("false")
            && acctList.get(i).contains(cardfull)) {
            var params = acctList.get(i).split(",");
            acc = getAccMap(params);
            map.put(String.valueOf(i), acc);
        }
    }
    return map;
}

function getCardBinList(beginHtml) {
    var map = new HashMap();
    var card = new HashMap();
    var cardList = RegexUtils.GetList(beginHtml,
        "cardBinList.add\\(new CardBin\\(([^;]*?)\\)");
    for (var i = 0; i < cardList.size(); i++) {
        var params = cardList.get(i).split(",");
        card = getcardMap(params);
        map.put(String.valueOf(i), card);
    }
    return map;
}

function getcardMap(params) {
    var card = new HashMap();
    for (var i = 0; i < params.length; i++) {
        switch (i) {
            case 0:
                card.put("cardBin", replaceParams(params[i]));
                break;
            case 1:
                card.put("cardType", replaceParams(params[i]));
                break;
            case 2:
                card.put("cardAreaRule", replaceParams(params[i]));
                break;
            case 3:
                card.put("cardLen", replaceParams(params[i]));
                break;
            case 4:
                card.put("func", replaceParams(params[i]));
                break;
            case 5:
                card.put("currlist", replaceParams(params[i]));
                break;
            case 6:
                card.put("EMVCard", replaceParams(params[i]));
                break;
            default:
                break;
        }
    }
    return card;
}

function getcardtype(cardnum, cardBinList) {
    var get_cardtype_init = "nocardbin";
    var len = 5;
    var acc = new HashMap();
    for each(var ms
in
    cardBinList.entrySet()
)
    {
        acc = ms.getValue();
        var cardBin = acc.get("cardBin");
        len = cardBin.length();
        if (cardnum.length() >= cardBin.length()
            && cardnum.substring(0, len).equals(cardBin)) {
            return acc.get("cardType");
        }
    }
    return get_cardtype_init;

}

function getAcctSelList(beginHtml, cardfull) {
    var map = new HashMap();
    var acc = new HashMap();
    var acctList = RegexUtils.GetList(beginHtml, "acctList.add\\(new Account\\(([^;]*?)\\)");
    for (var i = 0; i < acctList.size(); i++) {
        if (acctList.get(i).contains("true")
            && acctList.get(i).contains(cardfull)) {
            var params = acctList.get(i).split(",");
            acc = getAccMap(params);
            map.put(String.valueOf(i), acc);
        }
    }
    return map;
}

function getAccMap(params) {
    var acc = new HashMap();
    for (var i = 0; i < params.length; i++) {
        switch (i) {
            case 0:
                acc.put("isRegistedCard", replaceParams(params[i]));
                break;
            case 1:
                acc.put("cardNum", replaceParams(params[i]));
                break;
            case 2:
                acc.put("acctCode", replaceParams(params[i]));
                break;
            case 3:
                acc.put("acctNum", replaceParams(params[i]));
                break;
            case 4:
                acc.put("cardOwnerMark", replaceParams(params[i]));
                break;
            case 5:
                acc.put("cardOwnerType", replaceParams(params[i]));
                break;
            case 6:
                acc.put("acctType", replaceParams(params[i]));
                break;
            case 7:
                acc.put("acctDesc", replaceParams(params[i]));
                break;
            case 8:
                acc.put("isQryAcctList", replaceParams(params[i]));
                break;
            case 9:
                acc.put("cardAlias", replaceParams(params[i]));
                break;
            case 10:
                acc.put("acctAlias", replaceParams(params[i]));
                break;
            case 11:
                acc.put("acctProp", replaceParams(params[i]));
                break;
            case 12:
                acc.put("areaCode", replaceParams(params[i]));
                break;
            case 13:
                acc.put("areaName", replaceParams(params[i]));
                break;
            case 14:
                acc.put("regMode", replaceParams(params[i]));
                break;
            case 15:
                acc.put("acctlist_openregsign", replaceParams(params[i]));
                break;
            case 16:
                acc.put("getDescString", replaceParams(params[i]));
                break;
            case 17:
                acc.put("getDesc", replaceParams(params[i]));
                break;
            case 18:
                acc.put("auth", replaceParams(params[i]));
                break;
            case 19:
                acc.put("cityCard", replaceParams(params[i]));
                break;
            case 20:
                acc.put("dcrFlag", replaceParams(params[i]));
                break;
            case 21:
                acc.put("jointlyAcct", replaceParams(params[i]));
                break;
            case 22:
                acc.put("unionNum", replaceParams(params[i]));
                break;
            case 23:
                acc.put("agrFlag", replaceParams(params[i]));
                break;
            case 24:
                acc.put("RemitTRANLAG", replaceParams(params[i]));
                break;
            case 25:
                acc.put("MGACCNO", replaceParams(params[i]));
                break;
            case 26:
                acc.put("YJPHONE", replaceParams(params[i]));
                break;
            case 27:
                acc.put("CLFLAG", replaceParams(params[i]));
                break;
            case 28:
                acc.put("FUNDNO", replaceParams(params[i]));
                break;
            case 29:
                acc.put("OPENDATE", replaceParams(params[i]));
                break;
            case 30:
                acc.put("skFlag", replaceParams(params[i]));
                break;
            case 31:
                acc.put("skNo", replaceParams(params[i]));
                break;
            case 32:
                acc.put("ftFlag", replaceParams(params[i]));
                break;
            case 33:
                acc.put("isEAccount", replaceParams(params[i]));
                break;
            case 34:
                acc.put("classification", replaceParams(params[i]));
                break;
            case 35:
                acc.put("acctTypeDesc", replaceParams(params[i]));
                break;
            case 36:
                acc.put("getDescStringForByCheckmode", replaceParams(params[i]));
                break;
            case 37:
                acc.put("getDescStringForShow", replaceParams(params[i]));
                break;
            default:
                break;
        }
    }
    return acc;
}

function replaceParams(param) {
    return param.replaceAll("'|\"", "");
}

function isHomeCardFuc(value) {
    if (value.indexOf("homeCard") != -1) {
        return true;
    } else {
        return false;
    }
}

/**
 * 借记卡解析每个月的详单
 * @param expList
 * @param bills
 * @param yearMoth
 * @param card_num
 */
function getDetailBillByDateNew(expList, bills, yearMoth, card_num) {
    try{
        var billAllData = new BillAllData();
        var shopping_sheets = new ArrayList();// 消费记录

        billAllData.setBankName("工商银行");
        billAllData.setBillId(UUID.randomUUID().toString());
        billAllData.setInstallments(new ArrayList());

        billAllData.setBillMonth(yearMoth);
        billAllData.setBillType("");
        billAllData.setBillDate(yyyy_MM_dd_PARSER.parse(yearMoth + "-" + "01"));
        var newbalance = null;

        // 设置该类型为0
        var bigDecimal = null;
        // 以下数据页面无
        billAllData.setMinPayment(bigDecimal);
        billAllData.setInterest(bigDecimal);
        billAllData.setLastBalance(bigDecimal);
        billAllData.setLastPayment(bigDecimal);
        billAllData.setNewCharges(bigDecimal);
        // 信用额度相关
        billAllData.setCreditLimit(bigDecimal);
        billAllData.setCashLimit(bigDecimal);
        // 美元相关---------先暂且设置为0
        billAllData.setUsdCashLimit(bigDecimal);
        billAllData.setUsdCreditLimit(bigDecimal);
        billAllData.setUsdInterest(bigDecimal);
        billAllData.setUsdLastBalance(bigDecimal);
        billAllData.setUsdLastPayment(bigDecimal);
        billAllData.setUsdMinPayment(bigDecimal);
        billAllData.setUsdNewBalance(bigDecimal);
        billAllData.setUsdNewCharges(bigDecimal);
        var i = 1;
        for each(var exp in expList)
        {
            var trans_date = yyyy_MM_dd_HH_mm_ss_FORMAT.format(exp.getTransDate());
            if (trans_date.contains(yearMoth)) {
                exp.setOrderIndex(i);
                shopping_sheets.add(exp);
                i = i + 1;
            }
        }
        billAllData.setNewBalance(newbalance);
        billAllData.setShoppingSheets(shopping_sheets);
        if (shopping_sheets.size() != 0) {
            bills.add(billAllData);
        }

    }catch (e){
        logger.error("{},借记卡{}月份详单抓取异常:{}",context.get(Constants.LUA_TASK_KEY),yearMoth,e);
    }

}

function getYearOrDayString(num) {
    var mon = "";
    if (String.valueOf(num).length() == 1) {
        mon = "0" + String.valueOf(num);
    } else {
        mon = String.valueOf(num);
    }
    return mon;
}

function paraseDetailHtml(detailHtml, loandata, chickHtml, cardfull) {
    try {
        var doc = Jsoup.parse(detailHtml);
        var tbls = doc.select("[class='tblWidth']");
        if(tbls.size() > 0){
            var tbl = tbls.get(3);
            if(tbl.getElementsByTag("a").size()>0){
                var a = tbl.getElementsByTag("a").get(0);
                var href = a.attr("href");
                var params = href.split("'");
                if (params.length == 15) {
                    var b = tbl.getElementsByTag("a").get(1);
                    href = b.attr("href");
                    params = href.split("'");
                }
                paraseHisform(detailHtml, loandata);
                var hisForm = gs_hisform_next(params[1], params[3], params[5],params[7], params[9], params[11], params[13], params[15],loandata, detailHtml, chickHtml, cardfull);
            }else{
                logger.error("工商银行 taskKey:{} paraseDetailHtml()方法中  tbl.getElementsByTag(\"a\").size()=0",context.get(LUA_TASK_KEY));
            }
        }else{
            logger.error("工商银行 taskKey:{} paraseDetailHtml()方法中tbls.size()=0",context.get(LUA_TASK_KEY));
        }
        logger.info("");
    } catch (e) {
        logger.error("工商银行 taskKey:{} paraseDetailHtml()方法中发生异常信息：{}",context.get(LUA_TASK_KEY), e);
        statCaughtException(context, e);
    }
}

function gs_hisform_next(theform, begin_num,sysMark, nexttime, insum, outsum,ishere, flag, loandata,detailHtml, chickHtml, cardfull) {
    loandata.put("onoffDJFlag", "");
    loandata.put("onoffJJFlag", "2");
    loandata.put("ACSTYPE", "");
    loandata.put("ACAPPNO", "");
    loandata.put("SKflag", "0");

    loandata.put("ishere", ishere);

    var account = getAcctSelList(
        detailHtml, cardfull);
    var accountNo = "0";
    var acc = new HashMap();
    for each(var m in account.entrySet()){
        accountNo = m.getKey();
        acc = m.getValue();
    }
    var cardBinList = getCardBinList(chickHtml);
    var cardtype1 = getcardtype(cardfull, cardBinList);

    var account1 = getAcctSelList2(detailHtml, cardfull);
    var accountNo1 = "0";
    var acc1 = new HashMap();
    for each(var m1 in account1.entrySet()){
        accountNo1 = m1.getKey();
        acc1 = m1.getValue();
    }

    var card_num = acc.get("cardNum");
    if (!(accountNo1 == "no" || accountNo1 == "dr" || accountNo1 == "cr")) {
        if (acc1.get("acctCode").equals("000")
            || acc1.get("acctCode").equals("00000")) {
            loandata.put("qaccf", "1");
        } else {
            loandata.put("qaccf", "0");
        }
    }

    var cardtype2 = acc1.get("acctType");

    if (cardtype1 == "003" && cardtype2 == "011") {
        loandata.put("isupdate", "1");
    } else {
        loandata.put("isupdate", "0");
    }
    loandata.put("acctSelList", accountNo);
    loandata.put("YETYPE", "0");
    loandata.put("acctSelList2", accountNo1);
    loandata.put("styFlag", "0");

    var acctIndex = checkStringIsNull(loandata.get("acctIndex"));
    var subObj0 = checkStringIsNull(loandata.get("Begin_pos"));
    var subObj1 = checkStringIsNull(loandata.get("cardNum"));
    var subObj2 = checkStringIsNull(loandata.get("acctCode"));
    var subObj3 = checkStringIsNull(loandata.get("acctNum"));
    var subObj4 = checkStringIsNull(loandata.get("init_flag"));
    var subObj5 = checkStringIsNull(loandata.get("cardType"));
    var subObj6 = checkStringIsNull(loandata.get("queryType"));
    var subObj7 = checkStringIsNull(loandata.get("timestmp"));
    var subObj8 = checkStringIsNull(loandata.get("incomeSum"));
    var subObj9 = checkStringIsNull(loandata.get("payoutSum"));
    var subObj10 = checkStringIsNull(loandata.get("type"));
    var subObj11 = checkStringIsNull(loandata.get("pageflag"));
    var subObj12 = checkStringIsNull(loandata.get("cardAlias"));
    var subObj13 = checkStringIsNull(loandata.get("acctAlias"));
    var subObj14 = checkStringIsNull(loandata.get("acctSelList2"));
    var subObj15 = checkStringIsNull(loandata.get("flag"));

    subObj11 = "2";
    subObj10 = "browser";
    subObj7 = nexttime;
    subObj8 = insum;
    subObj9 = outsum;
    subObj15 = flag;
    subObj5 = acc.get("acctType");

    subObj12 = acc.get("cardAlias");
    if (!(subObj14.equals("no") || subObj14.equals("dr") || subObj14
            .equals("cr"))) {
        accountNo = subObj14;
        subObj13 = acc1.get("acctAlias");
        loandata.put("acctTypeName", acc1.get("acctType"));
    } else {
        if (subObj5.equals("003") || subObj5.equals("011")) {
            loandata.put("acctTypeName", "01");
        }
    }
    acctIndex = accountNo1;
    if (sysMark == "00" || sysMark == "01") {

        if (!(accountNo1.equals("no") || accountNo1.equals("dr") || accountNo1
                .equals("cr")))
            loandata.put("acctIndex", accountNo1);
    }
    accountNo = acctIndex;
    loandata.put("acctType", acc1.get("acctType"));
    subObj0 = begin_num;
    subObj1 = acc1.get("cardNum");
    subObj2 = acc1.get("acctCode");
    subObj3 = acc1.get("acctNum");
    subObj4 = "3";

    if (subObj5.equals("011")
        && !(loandata.get("acctType").equals("20")
            || loandata.get("acctType").equals("21")
            || loandata.get("acctType").equals("22")
            || loandata.get("acctType").equals("23") || loandata
                .get("acctType").equals("24")))
        subObj6 = "0";
    else if (subObj5.equals("003")
        && !(loandata.get("acctType").equals("20")
            || loandata.get("acctType").equals("21")
            || loandata.get("acctType").equals("22")
            || loandata.get("acctType").equals("23") || loandata
                .get("acctType").equals("24")))
        subObj6 = "1";
    else if (loandata.get("acctType").equals("20")
        || loandata.get("acctType").equals("21"))
        subObj6 = "3";
    else if (subObj5.equals("999"))
        subObj6 = "8";
    else
        subObj6 = "2";

    loandata.put("acctIndex", acctIndex);
    loandata.put("Begin_pos", subObj0);
    loandata.put("cardNum", subObj1);
    loandata.put("acctCode", subObj2);
    loandata.put("acctNum", subObj3);
    loandata.put("init_flag", subObj4);
    loandata.put("cardType", subObj5);
    loandata.put("queryType", subObj6);
    loandata.put("timestmp", subObj7);
    loandata.put("incomeSum", subObj8);
    loandata.put("payoutSum", subObj9);
    loandata.put("type", subObj10);
    loandata.put("pageflag", subObj11);
    loandata.put("cardAlias", subObj12);
    loandata.put("acctAlias", subObj13);
    loandata.put("acctSelList2", subObj14);
    loandata.put("flag", subObj15);

    return "";
}

function paraseExpense(expList, detailHtml, card_num) {
    var doc = Jsoup.parse(detailHtml);
    var tbls = doc.select("[class='lst tblWidth']");
    if (tbls.size() == 0) {
        return false;
    }
    var tbl = tbls.get(0);
    var trs = tbl.select("tr");
    for (var i = 1; i < trs.size(); i++) {
        var exp = new Expense();
        var tr = trs.get(i);
        var tds = tr.select("td");
        exp.setId(UUID.randomUUID().toString());
        exp.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(tds.get(0).text() + " 00:00:00"));
        var money = tds.get(2).text().replaceAll(",", "").trim();
        if (money.contains("-")) {
            exp.setAmountMoney(getBigDecimalByString(money.replaceAll("-",
                "")));
        } else {
            exp.setAmountMoney(getBigDecimalByString(money).negate());
        }
        exp.setBalance(getBigDecimalByString(tds.get(4).text()));
        exp.setCardNum("");
        var trans_addr = tds.get(1).text();
        exp.setRemark("");
        exp.setDescription(tds.get(1).text());
        if(exp.getDescription().contains("代付")){
            exp.setCategory("TRANSFER");
        }else{
            exp.setCategory(CategoryUtil.getDebitCategory(BankCode.ICBC, exp.getDescription(), exp.getAmountMoney().toString()));
        }
        exp.setCurrencyType(CreditResultUtil.convertCurr(tds.get(3).text()
            .replaceAll(",", "").trim()));
        exp.setNameOnOppositeCard(tds.get(5).text());
        exp.setOppositeBank("");
        exp.setOppositeCardNo("");
        // exp.setOrderIndex(i++);
        exp.setPostDate(yyyy_MM_dd_PARSER.parse(tds.get(0).text()));
        exp.setCardNum(card_num);
        // exp.setRemark("");
        exp.setTransAddr(trans_addr.trim());
        exp.setTransChannel("");
        exp.setTransMethod("");
        expList.add(exp);
    }
    if (detailHtml.contains("【上一页】") && !detailHtml.contains("【下一页】")) {
        return false;
    }
    return true;
}

function paraseBalance(j, kabaos, cardfull,
                       creditCardAllData) {
    var span_blance = kabaos.get(j).getElementById(
        "span_blance_" + cardfull.replaceAll(" ", ""));
    if (span_blance.text().contains("卡片状态不正常")) {
        creditCardAllData.setCreditLimit(null);
        creditCardAllData.setBalance(null);
        return;
    }
    var trs = span_blance.select("tr");
    var tr = trs.get(0);
    var tds = tr.select("td");
    var currtBalance = tds.get(1).text();
    var availBalance = tds.get(2).text();
    var currt = getBigDecimalByString(currtBalance);
    var avail = getBigDecimalByString(availBalance);
    var credit_limit = avail.subtract(currt).doubleValue();
    var df = new DecimalFormat(".##");
    var st = df.format(credit_limit);
    creditCardAllData.setCreditLimit(new BigDecimal(st));
    creditCardAllData.setBalance(avail);
}

/**
 * 这是从信用卡的Balance字段
 * @param balance
 * @param maps
 * @param creditCardAllData
 */
function getCreditCardBalanceSuccsedGs(balance, maps, creditCardAllData) {
    try {
        var json = JSON.parseObject(balance);
        var rkArrayjson = json.getJSONArray("rd");
        if (rkArrayjson == null) {
            creditCardAllData.setBalance(null);
            return;
        }
        var rd = rkArrayjson.getJSONObject(0);
        var dcrFlag = maps.get("dcrFlag");
        if (dcrFlag == null) {
            dcrFlag = "";
        }
        var drcrFlag = maps.get("drcrFlag");
        if (drcrFlag == null) {
            drcrFlag = "";
        }
        var cardType = maps.get("acctType");
        if (cardType == null) {
            cardType = "";
        }

        var balances = rd.getString("balance");
        if (balances == null) {
            creditCardAllData.setBalance(null);
        } else {
            balances = balances.substring(0, balances.length() - 2);
            creditCardAllData.setBalance(new BigDecimal(balances));
        }
    }catch (e){
         logger.error("{},信用卡Balance异常:{}",context.get(Constants.LUA_TASK_KEY),e);
    }

}

function parseBalanceParams(j, kabaos,
                            cardfull, accListMap) {
    var span_blance = kabaos.get(j).getElementById(
        "span_blance_" + cardfull.replaceAll(" ", ""));
    var span_i = span_blance.getElementsByTag("i").get(0);
    var onclick = span_i.attr("onclick");
    logger.info(onclick);
    var param = onclick.split("'");
    var map = new LinkedHashMap();
    map.put("BalanceLight", param[1]);
    map.put("cardNum", param[3]);
    map.put("acctNum", param[5]);
    map.put("cardType", param[7]);
    map.put("acctCode", param[9]);
    map.put("currType", param[11]);
    map.put("cashSign", param[13]);
    map.put("operatorFlag", param[15]);
    if (param.length > 17) {
        map.put("align", param[17]);
        map.put("skFlag", param[19]);
    } else {
        map.put("align", "");
        map.put("skFlag", "");
    }

    /*
     * {"method":"get","url":
     * "https://epass.icbc.com.cn/login/login.jsp?StructCode=1&orgurl=0&STNO=30"
     * } {"BalanceLight":"blance_6222020912002509988","cardNum":
     * "6222020912002509988"
     * ,"acctNum":"","cardType":"","acctCode":"00000","currType"
     * :"","cashSign":"","operatorFlag":"0","method":"get_balance_params"}
     * {"method":"gs_bill_list"} {"method":"show_noff"}
     */
    map.put("SessionId", accListMap.get("dse_sessionId"));
    var balance_params = get_balance_params(map);
    logger.info("工商银行 taskKey: {} 基本信息：余额参数： {}", context.get(LUA_TASK_KEY), balance_params);
    return balance_params;
}

function get_balance_params(map) {
    var paramsMap = new HashMap();
    if (map.get("currType") == null || map.get("currType").equals("")) {
        map.put("currType", "001");
    }
    if (map.get("cashSign") == null || map.get("cashSign").equals("")) {
        map.put("cashSign", "0");
    }

    paramsMap.put("SessionId", map.get("SessionId"));
    paramsMap.put("cardNum", map.get("cardNum"));
    paramsMap.put("acctNum", map.get("acctNum"));
    paramsMap.put("acctType", map.get("cardType"));
    paramsMap.put("acctCode", map.get("acctCode"));
    paramsMap.put("cashSign", map.get("cashSign"));
    paramsMap.put("currType", map.get("currType"));
    paramsMap.put("align", map.get("align"));
    paramsMap.put("operatorFlag", map.get("operatorFlag"));
    paramsMap.put("tranflag", "1");
    paramsMap.put("skFlag", map.get("skFlag"));
    paramsMap.put("tranCode", "A00012");
    return paramsMap;
}

function getBigDecimalByString(val) {
    if (val == null)
        return null;
    val = val.replaceAll(",", "");
    val = val.replaceAll("/RMB", "");
    val = val.replaceAll("人民币：| ", "");
    val = val.replaceAll("美元", "");
    val = val.replaceAll(" ", "");
    val = val.trim();
    var bigDecimal = new BigDecimal(val);
    return bigDecimal;
}

function isStringToNumber(str) {
    var pattern = Pattern.compile("^[A-Za-z0-9]+$");
    var match = pattern.matcher(str);
    return match.matches();
}

function getFilePath() {
    var taskKey = context.get(LUA_TASK_KEY);
    var path = "d:\\htmlStorage" + "\\" + "BANK" + "\\" + "20" + taskKey.substring(0, 2) + "\\" + taskKey.substring(2, 4) + "\\" + taskKey.substring(4, 6) + "\\" + "ICBC" + "\\" + taskKey + "\\";
    logger.info("任务{}路径：{}", taskKey, path);
    return path;
}

function checkFileError() {
    var path = getFilePath();
    var f = new File(path);
    if (!f.exists()) {
        logger.info(path + " not exists");
        return false;
    }

    var fa = f.listFiles();
    for (var i = 0; i < fa.length; i++) {
        var fs = fa[i];
        if (fs.isFile()) {
            System.out.println(fs.getPath());
            var html = FileUtils.readFileToString(
                new File(fs.getPath()), "utf-8");
            if (html.contains("您已经成功退出")) {
                return true;
            }
        }
    }
    return false;
}

var luaFuncs = {
    checkControlAvailable:function(){
        var map = new HashMap();
        map.put("method","checkControlAvailable");
        return sendAndReceive(map)
    },
    typeUsername: function (cardNo) {
        var map = new LinkedHashMap();
        map.put("method", "typeUsername");
        map.put("username", cardNo);
        return sendAndReceive(map);
    },
    whichPage: function(){
        var map = new LinkedHashMap();
        map.put("method", "checkWhichPageAfterClickLogin");
        return sendAndReceive(map);

    },
    store_Img_gs: function () {
        var map = new LinkedHashMap();
        map.put("method", "store_Img_gs");
        return sendAndReceive(map);
    },

    typePassword: function (passWord) {
        var map = new LinkedHashMap();
        map.put("method", "typePassword");
        map.put("password", passWord)
        return sendAndReceive(map);
    },

    gs_input_code: function (code) {
        var map = new LinkedHashMap();
        map.put("method", "gs_input_code");
        map.put("verifyCode", code);
        return sendAndReceive(map);
    },
    typeCaptcha: function (code) {
        var map = new LinkedHashMap();
        map.put("method", "typeCaptcha");
        map.put("verifyCode", code);
        return sendAndReceive(map);
    },
    clickLoginButton: function () {
        var map = new LinkedHashMap();
        map.put("method", "clickLoginButton");
        return sendAndReceive(map);
    },

    clickSmsSpan: function () {
        var map = new LinkedHashMap();
        map.put("method", "clickSmsSpan");
        return sendAndReceive(map);
    },

    sendSms: function () {
        var map = new LinkedHashMap();
        map.put("method", "sendSms");
        return sendAndReceive(map);
    },

    typeSms: function (verifySms) {
        var map = new LinkedHashMap();
        map.put("method", "typeSms");
        map.put("verifySms", verifySms);
        lp.Send(JSON.toJSONString(map));
        return lp.Receive();
    },

    getSmsCaptcha: function () {
        var map = new LinkedHashMap();
        map.put("method", "getSmsCaptcha");
        return sendAndReceive(map);
    },

    typeSmsCaptcha: function (code) {
        var map = new LinkedHashMap();
        map.put("method", "typeSmsCaptcha");
        map.put("smscode", code);
        return sendAndReceive(map);
    },

    clickConfirmButton: function () {
        var map = new LinkedHashMap();
        map.put("method", "clickConfirmButton");
        return sendAndReceive(map);
    },

    changeRadio: function () {
        var map = new LinkedHashMap();
        map.put("method", "changeRadio");
        return sendAndReceive(map);
    },

    closeFirstAD: function () {
        var map = new LinkedHashMap();
        map.put("method", "closeFirstAD");
        return sendAndReceive(map);
    },

    gs_bill_list: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_bill_list");
        return sendAndReceive(map);
    },

    gs_card_info: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_card_info");
        return sendAndReceive(map);
    },

    get_html_gs: function () {
        var map = new LinkedHashMap();
        map.put("method", "get_html_gs");
        return sendAndReceive(map);
    },

    gs_close_notice: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_close_notice");
        return sendAndReceive(map);
    },

    gs_get_cardlist: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_get_cardlist");
        return sendAndReceive(map);
    },

    gs_chick_detail: function (li) {
        var map = new LinkedHashMap();
        map.put("method", "gs_chick_detail");
        map.put("gsli", li);
        return sendAndReceive(map);
    },

    gs_update_date: function (beginDate) {
        var map = new LinkedHashMap();
        map.put("method", "gs_update_date");
        map.put("beginDate", beginDate);
        return sendAndReceive(map);
    },


    gs_bill_listG: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_bill_listG");
        return sendAndReceive(map);
    },

    gs_get_cardlistG: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_get_cardlistG");
        return sendAndReceive(map);
    },

    gs_click_user: function (li) {
        var map = new LinkedHashMap();
        map.put("method", "gs_click_user");
        map.put("gsli", li);
        return sendAndReceive(map);
    },

    gs_user_html: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_user_html");
        return sendAndReceive(map);
    },

    gs_click_return: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_click_return");
        return sendAndReceive(map);
    },

    gs_click_bills: function (li) {
        var map = new LinkedHashMap();
        map.put("method", "gs_click_bills");
        map.put("gsli", li);
        return sendAndReceive(map);
    },

    gs_get_bills: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_get_bills");
        return sendAndReceive(map);
    },

    getImagecodePath: function () {
        var map = new LinkedHashMap();
        map.put("method", "getImagecodePath");
        return sendAndReceive(map);
    },

    closeSecondAD: function () {
        var map = new LinkedHashMap();
        map.put("method", "closeSecondAD");
        return sendAndReceive(map);
    },

    check_login: function () {
        var map = new LinkedHashMap();
        map.put("method", "check_login");
        return sendAndReceive(map);
    },

    closeIndexHelp: function () {
        var map = new LinkedHashMap();
        map.put("method", "closeIndexHelp");
        return sendAndReceive(map);
    },

    SetLocationHref_gs: function (url) {
        var map = new LinkedHashMap();
        map.put("url", url);
        map.put("method", "SetLocationHref_gs");
        return sendAndReceive(map);
    },

    /**
     *
     * @return
     */
    setSizeAndShow: function () {
        var map = new LinkedHashMap();
        map.put("method", "setSizeAndShow");
        return sendAndReceive(map);
    },

    removeAD: function () {
        var map = new LinkedHashMap();
        map.put("method", "removeAD");
        return sendAndReceive(map);
    },

    get_login_code_gs_again: function () {
        var map = new LinkedHashMap();
        map.put("method", "get_login_code_gs_again");
        return sendAndReceive(map);
    },

    waitLoadOk: function () {
        var map = new LinkedHashMap();
        map.put("method", "waitLoadOk");
        return sendAndReceive(map);
    },

    call_return: function () {
        var map = new LinkedHashMap();
        map.put("method", "call_return");
        return sendAndReceive(map);
    },

    get_picture_gs: function () {
        var map = new LinkedHashMap();
        map.put("method", "get_picture_gs");
        return sendAndReceive(map);
    },

    GetScreenShots: function () {
        var map = new LinkedHashMap();
        map.put("method", "GetScreenShots");
        return sendAndReceive(map);
    },

    gs_doubleIframe_click_id: function () {
        var map = new LinkedHashMap();
        map.put("method", "gs_doubleIframe_click_id");
        return sendAndReceive(map);
    },

    clickQuXiao: function () {
        var map = new LinkedHashMap();
        map.put("method", "clickQuXiao");
        return sendAndReceive(map);
    },

    ajax_get_code: function (url) {
        var map = new LinkedHashMap();
        map.put("method", "ajax_get_code");
        map.put("url", url);
        return sendAndReceive(map);
    },
    icbc_click_frame: function () {
        var map = new LinkedHashMap();
        map.put("method", "icbc_click_frame");
        return sendAndReceive(map);
    },
    get_html_all: function () {
        var map = new LinkedHashMap();
        map.put("method", "get_html_all");
        return sendAndReceive(map);
    },
    click_reset_icbc: function () {
        var map = new LinkedHashMap();
        map.put("method", "click_reset_icbc");
        return sendAndReceive(map);
    },
    get_html_gb2312: function () {
        var map = new LinkedHashMap();
        map.put("method", "get_html_gb2312");
        return sendAndReceive(map);
    },
    getSecondLoginHtmlMsg:function () {
        var map = new LinkedHashMap();
        map.put("method", "getSecondLoginHtmlMsg");
        return sendAndReceive(map);
    },
    clickImage:function () {
        var map = new LinkedHashMap();
        map.put("method", "clickImage");
        return sendAndReceive(map);
    },
    getConfirmErrorMsg:function () {
        var map = new LinkedHashMap();
        map.put("method", "getConfirmErrorMsg");
        return sendAndReceive(map);
    },
    backgoto:function () {
        var map = new LinkedHashMap();
        map.put("method", "backgoto");
        return sendAndReceive(map);
    },
    clickGoOnButton:function () {
        var map = new LinkedHashMap();
        map.put("method", "clickGoOnButton");
        return sendAndReceive(map);
    },
    getIFrameHtml:function () {
        var map = new LinkedHashMap();
        map.put("method", "getIFrameHtml");
        return sendAndReceive(map);
    },
    locationHref:function (url) {
        var map = new LinkedHashMap();
        map.put("method", "locationHref");
        map.put("url", url);
        return sendAndReceive(map);
    },
    getURL:function () {
        var map = new LinkedHashMap();
        map.put("method", "getURL");
        return sendAndReceive(map);
    },
    hideScreenShot:function(){
        var map = new LinkedHashMap();
        map.put("method", "hideScreenShot");
        return sendAndReceive(map);
    },
    checkPreInfo: function(){
        var map = new LinkedHashMap();
        map.put("method", "checkPreInfo");
        return sendAndReceive(map);
    },
    checkAtomServiceFail : function(){
        var map = new LinkedHashMap();
        map.put("method", "checkAtomServiceFail");
        return sendAndReceive(map);
    },
    clearTemp : function(){
        var map = new LinkedHashMap();
        map.put("method", "clearTemp");
        return sendAndReceive(map);
    }

}

